Skip to content

feat(pre-processors): Add an optional 'default' parameter to the map pre-processor - #77

Closed
AudBrou wants to merge 1 commit into
mainfrom
cursor/map-pre-processor-default-value-f7f8
Closed

feat(pre-processors): Add an optional 'default' parameter to the map pre-processor#77
AudBrou wants to merge 1 commit into
mainfrom
cursor/map-pre-processor-default-value-f7f8

Conversation

@AudBrou

@AudBrou AudBrou commented Aug 11, 2026

Copy link
Copy Markdown

Context

There was no way to declare a fallback value for the map pre-processor: any value missing from values raised value '<x>' does not map to any values in [...], which fails the whole row.

Changes

  • map accepts an optional default parameter. When the incoming value is not one of the values keys, default is returned instead of raising. Omitting it keeps the current failing behaviour, and None is a valid default (a sentinel is used instead of None to detect "no default").
  • README documents the parameter, that an empty string can be used as a values key, and the pre-existing limitation that a raw empty value never reaches the pre-processors (it fails as required, or yields None with "optional": true).
  • Tests cover build-time parsing of the parameter, known/unknown values with a default, a None default, 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_value short-circuits empty raw values before running the transforms. Supporting that would need a separate field-level default option; happy to add it if wanted.

Validation

pytest (181 passed), ruff check, ruff format --check and basedpyright (0 errors) all pass.

Open in Web Open in Cursor 

…pre-processor

Co-authored-by: Audrey Brouard <AudBrou@users.noreply.github.com>
@AudBrou AudBrou closed this Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants