Skip to content

Commit

Permalink
[SNOW-1649176]: Fix inplace argument for Series objects derived fro…
Browse files Browse the repository at this point in the history
…m DataFrame columns. (#2210)

<!---
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-1649176

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.

Please write a short description of how your code change solves the
related issue.
  • Loading branch information
sfc-gh-rdurrani authored Sep 4, 2024
1 parent fe506ac commit afbc6f6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
- Stopped ignoring nanoseconds in `pd.Timedelta` scalars.
- Fixed AssertionError in tree of binary operations.
- Fixed bug in `Series.dt.isocalendar` using a named Series
- Fixed `inplace` argument for Series objects derived from DataFrame columns.

#### Behavior Change

Expand Down
20 changes: 18 additions & 2 deletions src/snowflake/snowpark/modin/pandas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,15 @@ def __getitem__(
)
if isinstance(result, Series):
result._parent = self.df
result._parent_axis = 0
# We need to determine which axis this Series was extracted from. We can do so
# by checking which axis' locator is slice(None). If row_loc == slice(None),
# that means that we are extracting from axis=1, and if col_loc == slice(None),
# that means we are extracting from axis=0. If `row_loc` is a BasePandasDataset
# then it is also an extraction along axis=0.
if not isinstance(row_loc, slice):
result._parent_axis = 0
else:
result._parent_axis = int(row_loc == slice(None))

return result

Expand Down Expand Up @@ -1181,7 +1189,15 @@ def __getitem__(

if isinstance(result, Series):
result._parent = self.df
result._parent_axis = 0
# We need to determine which axis this Series was extracted from. We can do so
# by checking which axis' locator is slice(None). If row_loc == slice(None),
# that means that we are extracting from axis=1, and if col_loc == slice(None),
# that means we are extracting from axis=0. If `row_loc` is a SnowflakeQueryCompiler
# then it is also an extraction along axis=0.
if not isinstance(row_loc, slice):
result._parent_axis = 0
else:
result._parent_axis = int(row_loc == slice(None))
return result

def _get_pandas_object_from_qc_view(
Expand Down
13 changes: 13 additions & 0 deletions tests/integ/modin/series/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,16 @@ def test_argument_negative(test_fillna_series, test_fillna_df):
expect_exception_type=TypeError,
assert_exception_equal=False,
)


@sql_count_checker(query_count=1)
def test_inplace_fillna_from_df():
def inplace_fillna(df):
df["B"].fillna(method="ffill", inplace=True)
return df

eval_snowpark_pandas_result(
pd.DataFrame([[1, 2, 3], [4, None, 6]], columns=list("ABC")),
native_pd.DataFrame([[1, 2, 3], [4, None, 6]], columns=list("ABC")),
inplace_fillna,
)

0 comments on commit afbc6f6

Please sign in to comment.