Harden salary parsing against malformed job-board data - #380
Open
codechrl wants to merge 1 commit into
Open
Conversation
Three crashes that could abort a scrape when a board returned an unusual
salary field:
- currency_parser raised ValueError on non-numeric text ('Negotiable',
'Competitive') because it reduced to '' and called float(''). It now returns
None, matching how callers already treat a missing value.
- LinkedIn _parse_job indexed salary_values[1] unconditionally, so a
single-value salary ('$120,000+', no range) raised IndexError; and int(None)
raised once currency_parser could return None. It now parses defensively and
only builds Compensation when both bounds are numeric.
- convert_to_annual raised KeyError on a missing 'interval' and TypeError on a
null min/max amount ('None *= n'). It now scales only present amounts and
no-ops on an unknown interval.
Adds tests/test_util_parsing.py covering all three.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three parsing paths could raise and abort a scrape when a job board returned an
unusual salary/compensation field. Each is a single malformed value taking down
more than its own row.
Changes
currency_parser(jobspy/util.py) — non-numeric salary text(
"Negotiable","Competitive") reduces to""and hitfloat("")→ValueError. Now returnsNone, matching how callers already treat a missingvalue.
_parse_job(jobspy/linkedin/__init__.py) — a single-valuesalary (
"$120,000+", no-range) indexedsalary_values[1]→IndexError; andint(None)raised oncecurrency_parsercan returnNone.Now parses defensively and only builds
Compensationwhen both bounds arenumeric.
convert_to_annual(jobspy/util.py) — raisedKeyErroron a missingintervalandTypeError(None *= n) on a nullmin/max. Now scales onlypresent amounts and no-ops on an unknown interval.
Testing
tests/test_util_parsing.pycovers all three (non-numeric → None, missinginterval no-op, null amount, and unchanged behavior for normal values). Existing
salary parsing for normal ranges is unaffected.