From 046d61152fbcac3e21f2d7c18ced48eae8e3b949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C3=A9cio=20Santos?= Date: Tue, 14 Jan 2025 21:06:33 -0500 Subject: [PATCH] feat: Support list in value matches mapping_spec 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"], ], } ] --- bdikit/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bdikit/api.py b/bdikit/api.py index 8ab8bb6..b6ba443 100644 --- a/bdikit/api.py +++ b/bdikit/api.py @@ -836,7 +836,7 @@ 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: @@ -844,7 +844,7 @@ def _create_mapper_from_value_matches(matches: List[ValueMatch]) -> DictionaryMa "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)