Skip to content

Commit

Permalink
refactor: Rename update_mappings() to merge_mappings()
Browse files Browse the repository at this point in the history
  • Loading branch information
aecio committed Jul 24, 2024
1 parent b87f980 commit 8fb62c4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bdikit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class ColumnMappingSpec(TypedDict):
mapper: ValueMapper


def update_mappings(
def merge_mappings(
mappings: MappingSpecLike, user_mappings: Optional[MappingSpecLike] = None
) -> List:
"""
Expand Down Expand Up @@ -704,7 +704,7 @@ def create_mapper(

if isinstance(input, Dict):
if all(k in input for k in ["source", "target"]):
# This could be the mapper created by update_mappings() or a
# This could be the mapper created by merge_mappings() or a
# specification defined by the user
if "mapper" in input:
if isinstance(input["mapper"], ValueMapper):
Expand Down
4 changes: 2 additions & 2 deletions examples/getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,7 @@
"source": [
"### Combining custom user mappings with suggested mappings\n",
"\n",
"Before generating a final harmonized dataset, we can combine the automatically generated value mappings with the fixed mappings provided by the user. To do so, we use `bdi.update_mappings()` function, which take a list of mappings (e.g., generated automatically) and a list of \"user-defined mapping overrides\" that will be combined with the first list of mappings and will take precedence whenever they conflict.\n",
"Before generating a final harmonized dataset, we can combine the automatically generated value mappings with the fixed mappings provided by the user. To do so, we use `bdi.merge_mappings()` function, which take a list of mappings (e.g., generated automatically) and a list of \"user-defined mapping overrides\" that will be combined with the first list of mappings and will take precedence whenever they conflict.\n",
"\n",
"In our example below, all mappings specified in the variable `user_mappings` will override the mappings in `value_mappings` generated by the `bdi.match_values()` function."
]
Expand Down Expand Up @@ -2787,7 +2787,7 @@
"]\n",
"\n",
"\n",
"harmonization_spec = bdi.update_mappings(value_mappings, user_mappings)\n"
"harmonization_spec = bdi.merge_mappings(value_mappings, user_mappings)\n"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,17 @@ def test_end_to_end_api_integration():
assert "tgt_column" in df_mapped.columns
assert df_mapped["tgt_column"].tolist() == ["apple", "banana", "orange", None]

# when: pass output of match_values() to update_mappings() and then to
# when: pass output of match_values() to merge_mappings() and then to
# materialize_mapping()
harmonization_spec = bdi.update_mappings(value_mappings, [])
harmonization_spec = bdi.merge_mappings(value_mappings, [])
df_mapped = bdi.materialize_mapping(df_source, harmonization_spec)

# then: the column must be ranamed and values must be mapped
assert isinstance(df_mapped, pd.DataFrame)
assert "tgt_column" in df_mapped.columns
assert df_mapped["tgt_column"].tolist() == ["apple", "banana", "orange", None]

# when: user mappings are specified in update_mappings()
# when: user mappings are specified in merge_mappings()
user_mappings = [
{
"source": "src_column",
Expand All @@ -261,7 +261,7 @@ def test_end_to_end_api_integration():
],
}
]
harmonization_spec = bdi.update_mappings(value_mappings, user_mappings)
harmonization_spec = bdi.merge_mappings(value_mappings, user_mappings)
df_mapped = bdi.materialize_mapping(df_source, harmonization_spec)

# then: user mappings take precedence, so the column must be ranamed and
Expand Down

0 comments on commit 8fb62c4

Please sign in to comment.