Skip to content

Commit

Permalink
feat: Support list in value matches mapping_spec
Browse files Browse the repository at this point in the history
This changes makes the mapping specification, allowing the "matches"
in the spec contain lists (in addition to tuples, which were already
supported). Example:

    mappings = [
        {
            "source": "src_column",
            "target": "tgt_column",
            "matches": [
                ["Red Apple", "APPLE"],
                ["Banana", "BANANA"],
                ["Oorange", "ORANGE"],
            ],
        }
    ]
  • Loading branch information
aecio committed Jan 15, 2025
1 parent f2e783c commit 046d611
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bdikit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,15 +836,15 @@ def _create_mapper_from_value_matches(matches: List[ValueMatch]) -> DictionaryMa
for match in matches:
if isinstance(match, ValueMatch):
mapping_dict[match.source_value] = match.target_value
elif isinstance(match, tuple) and len(match) == 2:
elif (isinstance(match, tuple) or isinstance(match, list)) and len(match) == 2:
if isinstance(match[0], str) and isinstance(match[1], str):
mapping_dict[match[0]] = match[1]
else:
raise ValueError(
"Tuple in matches must contain two strings: (source_value, target_value)"
)
else:
raise ValueError("Matches must be a list of ValueMatch objects or tuples")
raise ValueError("Matches must be a list of ValueMatch objects or tuples with two values.")
return DictionaryMapper(mapping_dict)


Expand Down

0 comments on commit 046d611

Please sign in to comment.