Skip to content

refactor: use replace over map_dict #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions functime/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _set_string_cache(df: pl.DataFrame):
# Reset categorical to string type
df = df.with_columns(pl.col(entity_col).cast(pl.Utf8))
df_new = df.with_columns(
pl.col(entity_col).map_dict(string_cache, return_dtype=pl.Int32)
pl.col(entity_col).replace(string_cache, return_dtype=pl.Int32, default=None)
)
inv_string_cache = {i: entity for entity, i in string_cache.items()}
return df_new, entity_col_dtype, string_cache, inv_string_cache
Expand All @@ -29,15 +29,17 @@ def _enforce_string_cache(
# Reset categorical to string type
df = df.with_columns(pl.col(entity_col).cast(pl.Utf8))
return df.with_columns(
pl.col(entity_col).map_dict(string_cache, return_dtype=pl.Int32)
pl.col(entity_col).replace(string_cache, return_dtype=pl.Int32, default=None)
)


def _reset_string_cache(
df: pl.DataFrame, inv_string_cache: Mapping[int, Union[int, str]], return_dtype
) -> pl.DataFrame:
return df.with_columns(
pl.col(df.columns[0]).map_dict(inv_string_cache, return_dtype=return_dtype)
pl.col(df.columns[0]).replace(
inv_string_cache, return_dtype=return_dtype, default=None
)
)


Expand Down
Loading