Skip to content
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

[SNOW-1527902]: Add support for limit parameter in fillna. #1891

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### New Features
- Added partial support for `Series.str.translate` where the values in the `table` are single-codepoint strings.
- Added support for `DataFrame.corr`.
- Added support for `limit` parameter in `fillna`.

#### Bug Fixes
- Fixed an issue when using np.where and df.where when the scalar 'other' is the literal 0.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/modin/supported/dataframe_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Methods
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``explode`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``ffill`` | P | | ``N`` if param ``limit`` is set |
| ``ffill`` | P | | ``N`` if param ``downcast`` is set. |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``fillna`` | P | | See ``ffill`` |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/source/modin/supported/series_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Methods
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``factorize`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``ffill`` | P | | ``N`` if parameter ``limit`` is set |
| ``ffill`` | P | | ``N`` if parameter ``downcast`` is set. |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``fillna`` | P | | See ``ffill`` |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8857,11 +8857,6 @@ def fillna(
BaseQueryCompiler
New QueryCompiler with all null values filled.
"""
# TODO: SNOW-891788 support limit
if limit:
ErrorMessage.not_implemented(
"Snowpark pandas fillna API doesn't yet support 'limit' parameter"
)
if downcast:
ErrorMessage.not_implemented(
"Snowpark pandas fillna API doesn't yet support 'downcast' parameter"
Expand All @@ -8883,12 +8878,18 @@ def fillna(
self._modin_frame = self._modin_frame.ensure_row_position_column()
if method_is_ffill:
func = last_value
window_start = Window.UNBOUNDED_PRECEDING
if limit is None:
window_start = Window.UNBOUNDED_PRECEDING
else:
window_start = -1 * limit
window_end = Window.CURRENT_ROW
else:
func = first_value
window_start = Window.CURRENT_ROW
window_end = Window.UNBOUNDED_FOLLOWING
if limit is None:
window_end = Window.UNBOUNDED_FOLLOWING
else:
window_end = limit
fillna_column_map = {
snowflake_quoted_id: coalesce(
snowflake_quoted_id,
Expand Down
27 changes: 21 additions & 6 deletions tests/integ/modin/frame/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ def test_fillna_df():
)


@pytest.fixture(scope="function")
def test_fillna_df_limit():
return native_pd.DataFrame(
[
[1, 2, np.nan, 4],
[np.nan, np.nan, 7, np.nan],
[np.nan, 10, np.nan, 12],
[np.nan, np.nan, 15, 16],
],
columns=list("ABCD"),
)


@pytest.fixture(scope="function")
def test_fillna_df_none_index():
# test case to make sure fillna only fill missing values in data columns not index columns
Expand Down Expand Up @@ -260,12 +273,14 @@ def test_value_scalar_inplace(test_fillna_df):
)


@sql_count_checker(query_count=0)
def test_value_scalar_limit_not_implemented(test_fillna_df):
df = pd.DataFrame(test_fillna_df)
msg = "Snowpark pandas fillna API doesn't yet support 'limit' parameter"
with pytest.raises(NotImplementedError, match=msg):
df.fillna(1, limit=1)
@sql_count_checker(query_count=1)
@pytest.mark.parametrize("limit", [1, 2, 3, 100])
@pytest.mark.parametrize("method", ["ffill", "bfill"])
def test_fillna_limit(test_fillna_df_limit, method, limit):
snow_df = pd.DataFrame(test_fillna_df_limit)
eval_snowpark_pandas_result(
snow_df, test_fillna_df_limit, lambda df: df.fillna(method=method, limit=limit)
)


@sql_count_checker(query_count=0)
Expand Down
18 changes: 18 additions & 0 deletions tests/integ/modin/series/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def test_fillna_series_2():
return native_pd.Series([np.nan, 2, np.nan, 0], list("abcd"))


@pytest.fixture(scope="function")
def test_fillna_series_limit():
return native_pd.Series(
[np.nan, 1, 2, np.nan, np.nan, np.nan, np.nan, 7, np.nan, 9]
)


@pytest.fixture(scope="function")
def test_fillna_df():
return native_pd.DataFrame(
Expand Down Expand Up @@ -125,6 +132,17 @@ def test_value_scalar(test_fillna_series):
)


@sql_count_checker(query_count=1)
@pytest.mark.parametrize("limit", [1, 2, 3, 100])
@pytest.mark.parametrize("method", ["ffill", "bfill"])
def test_fillna_limit(test_fillna_series_limit, limit, method):
eval_snowpark_pandas_result(
pd.Series(test_fillna_series_limit),
test_fillna_series_limit,
lambda s: s.fillna(method=method, limit=limit),
)


@sql_count_checker(query_count=1, join_count=1)
def test_value_series(test_fillna_series, test_fillna_series_2):
eval_snowpark_pandas_result(
Expand Down
Loading