Skip to content

Commit 6a3a77b

Browse files
[SNOW-1320248]: Fix inplace=True on Series objects derived from Series. (#2307)
<!--- Please answer these questions before creating your pull request. Thanks! ---> 1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR. <!--- In this section, please add a Snowflake Jira issue number. Note that if a corresponding GitHub issue exists, you should still include the Snowflake Jira issue number. For example, for GitHub issue #1400, you should add "SNOW-1335071" here. ---> Fixes SNOW-1320248 2. Fill out the following pre-review checklist: - [ ] I am adding a new automated test(s) to verify correctness of my new code - [ ] If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing - [ ] I am adding new logging messages - [ ] I am adding a new telemetry message - [ ] I am adding new credentials - [ ] I am adding a new dependency - [ ] If this is a new feature/behavior, I'm adding the Local Testing parity changes. 3. Please describe how your code solves the related issue. This PR fixes the inplace argument for Series functions where the Series is derived from another Series object (e.g. series = series.iloc[:4]; series.fillna(14, inplace=True)) --------- Co-authored-by: Hazem Elmeleegy <[email protected]>
1 parent 6554f82 commit 6a3a77b

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
- 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`.
2020
- Suppressed an unhelpful `SettingWithCopyWarning` that sometimes appeared when printing `Timedelta` columns.
21-
21+
- Fixed `inplace` argument for `Series` objects derived from other `Series` objects.
2222

2323
## 1.22.1 (2024-09-11)
2424
This is a re-release of 1.22.0. Please refer to the 1.22.0 release notes for detailed release content.

src/snowflake/snowpark/modin/plugin/extensions/series_overrides.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,25 @@ def __init__(
392392
self.name = name
393393

394394

395+
@register_series_accessor("_update_inplace")
396+
def _update_inplace(self, new_query_compiler) -> None:
397+
"""
398+
Update the current Series in-place using `new_query_compiler`.
399+
400+
Parameters
401+
----------
402+
new_query_compiler : BaseQueryCompiler
403+
QueryCompiler to use to manage the data.
404+
"""
405+
super(Series, self)._update_inplace(new_query_compiler=new_query_compiler)
406+
# Propagate changes back to parent so that column in dataframe had the same contents
407+
if self._parent is not None:
408+
if self._parent_axis == 1 and isinstance(self._parent, DataFrame):
409+
self._parent[self.name] = self
410+
else:
411+
self._parent.loc[self.index] = self
412+
413+
395414
# Since Snowpark pandas leaves all data on the warehouse, memory_usage's report of local memory
396415
# usage isn't meaningful and is set to always return 0.
397416
@_inherit_docstrings(native_pd.Series.memory_usage, apilink="pandas.Series")

tests/integ/modin/series/test_fillna.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44

55

6+
import string
7+
68
import modin.pandas as pd
79
import numpy as np
810
import pandas as native_pd
@@ -201,3 +203,17 @@ def inplace_fillna(df):
201203
native_pd.DataFrame([[1, 2, 3], [4, None, 6]], columns=list("ABC")),
202204
inplace_fillna,
203205
)
206+
207+
208+
@pytest.mark.parametrize("index", [list(range(8)), list(string.ascii_lowercase[:8])])
209+
@sql_count_checker(query_count=1, join_count=4)
210+
def test_inplace_fillna_from_series(index):
211+
def inplace_fillna(series):
212+
series.iloc[:4].fillna(14, inplace=True)
213+
return series
214+
215+
eval_snowpark_pandas_result(
216+
pd.Series([np.nan, 1, 2, 3, 4, 5, 6, 7], index=index),
217+
native_pd.Series([np.nan, 1, 2, 3, 4, 5, 6, 7], index=index),
218+
inplace_fillna,
219+
)

0 commit comments

Comments
 (0)