diff --git a/src/snowflake/snowpark/modin/plugin/PANDAS_CHANGELOG.md b/src/snowflake/snowpark/modin/plugin/PANDAS_CHANGELOG.md index 9afd0560f38..a48ca9a795f 100644 --- a/src/snowflake/snowpark/modin/plugin/PANDAS_CHANGELOG.md +++ b/src/snowflake/snowpark/modin/plugin/PANDAS_CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed `@udf` decorator when `packages=None` are specified preventing error in `Series.apply`. - Fixed incorrect regex used in `Series.str.contains`. - Fixed DataFrame's `__getitem__` with boolean DataFrame key. +- Fixed incorrect regex used in `DataFrame/Series.replace`. ## 1.14.0a2 (2024-04-18) diff --git a/src/snowflake/snowpark/modin/plugin/compiler/snowflake_query_compiler.py b/src/snowflake/snowpark/modin/plugin/compiler/snowflake_query_compiler.py index f8de1b8adc4..fb845dad90a 100644 --- a/src/snowflake/snowpark/modin/plugin/compiler/snowflake_query_compiler.py +++ b/src/snowflake/snowpark/modin/plugin/compiler/snowflake_query_compiler.py @@ -10395,7 +10395,7 @@ def replace( if native_pd.isna(k): cond = column.is_null() elif regex is True: - cond = column.regexp(pandas_lit(k)) + cond = column.regexp(pandas_lit(f".*{k}.*")) v = regexp_replace(subject=column, pattern=k, replacement=v) else: cond = column == k diff --git a/tests/integ/modin/frame/test_replace.py b/tests/integ/modin/frame/test_replace.py index 2d8daf4f0ec..6fa16275d83 100644 --- a/tests/integ/modin/frame/test_replace.py +++ b/tests/integ/modin/frame/test_replace.py @@ -23,6 +23,9 @@ def snow_df(): "to_replace, value", [ ("one", "ONE"), # scalar -> scalar + ("on", "ON"), # scalar prefix-> scalar + ("ne", "NE"), # scalar suffix-> scalar + ("n", "N"), # scalar infix-> scalar ("one", pd.NA), # scalar -> NULL ("one", None), # scalar -> None (pd.NA, "ONE"), # NULL -> scalar diff --git a/tests/integ/modin/series/test_replace.py b/tests/integ/modin/series/test_replace.py index cf01020faf8..6176b69f5f9 100644 --- a/tests/integ/modin/series/test_replace.py +++ b/tests/integ/modin/series/test_replace.py @@ -21,6 +21,9 @@ def snow_series(): "to_replace, value", [ ("one", "ONE"), # scalar -> scalar + ("on", "ON"), # scalar prefix-> scalar + ("ne", "NE"), # scalar suffix-> scalar + ("n", "N"), # scalar infix-> scalar ("one", pd.NA), # scalar -> NULL ("one", None), # scalar -> None (pd.NA, "ONE"), # NULL -> scalar