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-1320248]: Fix inplace=True on Series objects derived from Series. #2307

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

- Fixed a bug where an `Index` object created from a `Series`/`DataFrame` incorrectly updates the `Series`/`DataFrame`'s index name after an inplace update has been applied to the original `Series`/`DataFrame`.
- Suppressed an unhelpful `SettingWithCopyWarning` that sometimes appeared when printing `Timedelta` columns.

- Fixed `inplace` argument for `Series` objects derived from other `Series` objects.

## 1.22.1 (2024-09-11)
This is a re-release of 1.22.0. Please refer to the 1.22.0 release notes for detailed release content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,25 @@ def __init__(
self.name = name


@register_series_accessor("_update_inplace")
def _update_inplace(self, new_query_compiler) -> None:
"""
Update the current Series in-place using `new_query_compiler`.

Parameters
----------
new_query_compiler : BaseQueryCompiler
QueryCompiler to use to manage the data.
"""
super(Series, self)._update_inplace(new_query_compiler=new_query_compiler)
# Propagate changes back to parent so that column in dataframe had the same contents
if self._parent is not None:
if self._parent_axis == 1 and isinstance(self._parent, DataFrame):
sfc-gh-nkrishna marked this conversation as resolved.
Show resolved Hide resolved
self._parent[self.name] = self
else:
self._parent.loc[self.index] = self


# Since Snowpark pandas leaves all data on the warehouse, memory_usage's report of local memory
# usage isn't meaningful and is set to always return 0.
@_inherit_docstrings(native_pd.Series.memory_usage, apilink="pandas.Series")
Expand Down
16 changes: 16 additions & 0 deletions tests/integ/modin/series/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#


import string

import modin.pandas as pd
import numpy as np
import pandas as native_pd
Expand Down Expand Up @@ -201,3 +203,17 @@ def inplace_fillna(df):
native_pd.DataFrame([[1, 2, 3], [4, None, 6]], columns=list("ABC")),
inplace_fillna,
)


@pytest.mark.parametrize("index", [list(range(8)), list(string.ascii_lowercase[:8])])
@sql_count_checker(query_count=1, join_count=4)
def test_inplace_fillna_from_series(index):
def inplace_fillna(series):
series.iloc[:4].fillna(14, inplace=True)
return series

eval_snowpark_pandas_result(
pd.Series([np.nan, 1, 2, 3, 4, 5, 6, 7], index=index),
native_pd.Series([np.nan, 1, 2, 3, 4, 5, 6, 7], index=index),
inplace_fillna,
)
Loading