feat(pre-processors): Add an optional 'default' parameter to the map pre-processor - #77
Closed
AudBrou wants to merge 1 commit into
Closed
feat(pre-processors): Add an optional 'default' parameter to the map pre-processor#77AudBrou wants to merge 1 commit into
AudBrou wants to merge 1 commit into
Conversation
…pre-processor Co-authored-by: Audrey Brouard <AudBrou@users.noreply.github.com>
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.
Context
There was no way to declare a fallback value for the
mappre-processor: any value missing fromvaluesraisedvalue '<x>' does not map to any values in [...], which fails the whole row.Changes
mapaccepts an optionaldefaultparameter. When the incoming value is not one of thevalueskeys,defaultis returned instead of raising. Omitting it keeps the current failing behaviour, andNoneis a valid default (a sentinel is used instead ofNoneto detect "no default").valueskey, and the pre-existing limitation that a raw empty value never reaches the pre-processors (it fails as required, or yieldsNonewith"optional": true).Nonedefault, and mapping an empty string key.{ "key": "unit-of-measurement", "column-number": 12, "type": "int", "pre-processors": [ {"name": "map", "parameters": {"values": {"K": 0, "A": 1, "L": 2}, "default": 0}} ], }Notes
Mapping a truly empty column value still isn't possible, because
Field._process_raw_valueshort-circuits empty raw values before running the transforms. Supporting that would need a separate field-leveldefaultoption; happy to add it if wanted.Validation
pytest(181 passed),ruff check,ruff format --checkandbasedpyright(0 errors) all pass.