Skip to content

Commit

Permalink
fix: change value mapping logic
Browse files Browse the repository at this point in the history
Signed-off-by: seolmin <[email protected]>
  • Loading branch information
stat-kwon committed Jan 21, 2025
1 parent b555554 commit 608b1b7
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,24 @@ def apply_cases(self, filtered_df: pd.DataFrame) -> pd.DataFrame:
match = case["match"].strip()

if operator == "eq":
filtered_df.loc[filtered_df[key] == match, name] = value
if name not in filtered_df.columns:
filtered_df.loc[filtered_df[key] == match, name] = value
else:
filtered_df.loc[
(filtered_df[key] == match) & (filtered_df[name].isna()), name
] = value

elif operator == "regex":
filtered_df.loc[
filtered_df[key].str.contains(match, na=False), name
] = value
if name not in filtered_df.columns:
filtered_df.loc[
filtered_df[key].str.contains(match, na=False), name
] = value
else:
filtered_df.loc[
(filtered_df[key].str.contains(match, na=False))
& (filtered_df[name].isna()),
name,
] = value

if else_value is not None:
filtered_df.loc[filtered_df[name].isna(), name] = else_value
Expand Down

0 comments on commit 608b1b7

Please sign in to comment.