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-1664064: Suppress SettingWithCopyWarning for Timedelta columns. #2298

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

sfc-gh-mvashishtha marked this conversation as resolved.
Show resolved Hide resolved
- 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()
Loading