Skip to content

Commit

Permalink
SNOW-1664064: Suppress SettingWithCopyWarning for Timedelta columns. (#…
Browse files Browse the repository at this point in the history
…2298)

Fixes SNOW-1664064

---------
Signed-off-by: sfc-gh-mvashishtha <[email protected]>
  • Loading branch information
sfc-gh-mvashishtha authored Sep 17, 2024
1 parent e93cd68 commit 3f60507
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#### Bug Fixes

- 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.


## 1.22.1 (2024-09-11)
Expand Down
12 changes: 9 additions & 3 deletions src/snowflake/snowpark/modin/plugin/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,9 +1519,15 @@ def convert_str_to_timedelta(x: str) -> pd.Timedelta:
downcast_pandas_df.columns, cached_snowpark_pandas_types
):
if snowpark_pandas_type is not None and snowpark_pandas_type == timedelta_t:
downcast_pandas_df[pandas_label] = pandas_df[pandas_label].apply(
convert_str_to_timedelta
)
# By default, pandas warns, "A value is trying to be set on a
# copy of a slice from a DataFrame" here because we are
# assigning a column to downcast_pandas_df, which is a copy of
# a slice of pandas_df. We don't care what happens to pandas_df,
# so the warning isn't useful to us.
with native_pd.option_context("mode.chained_assignment", None):
downcast_pandas_df[pandas_label] = pandas_df[pandas_label].apply(
convert_str_to_timedelta
)

# Step 7. postprocessing for return types
if index_only:
Expand Down
9 changes: 9 additions & 0 deletions tests/integ/modin/types/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
#
import datetime
import warnings

import modin.pandas as pd
import pandas as native_pd
import pytest
from pandas.errors import SettingWithCopyWarning

from tests.integ.modin.sql_counter import sql_count_checker
from tests.integ.modin.utils import (
Expand Down Expand Up @@ -107,3 +109,10 @@ def test_timedelta_not_supported():
match="SnowflakeQueryCompiler::groupby_groups is not yet implemented for Timedelta Type",
):
df.groupby("a").groups()


@sql_count_checker(query_count=1)
def test_aggregation_does_not_print_internal_warning_SNOW_1664064():
with warnings.catch_warnings():
warnings.simplefilter(category=SettingWithCopyWarning, action="error")
pd.Series(pd.Timedelta(1)).max()

0 comments on commit 3f60507

Please sign in to comment.