diff --git a/DESCRIPTION.md b/DESCRIPTION.md index 4765edf346..69649fa89b 100644 --- a/DESCRIPTION.md +++ b/DESCRIPTION.md @@ -9,6 +9,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne # Release Notes - v3.18.0(TBD) - Added the `workload_identity_impersonation_path` parameter to support service account impersonation for Workload Identity Federation on GCP workloads only + - Print user related pandas warnings only once - v3.17.3(September 02,2025) - Enhanced configuration file permission warning messages. diff --git a/src/snowflake/connector/pandas_tools.py b/src/snowflake/connector/pandas_tools.py index afa3d7d2af..632c9f4ebe 100644 --- a/src/snowflake/connector/pandas_tools.py +++ b/src/snowflake/connector/pandas_tools.py @@ -42,6 +42,21 @@ logger = getLogger(__name__) +class PandasUserOnceWarnings(UserWarning): + """ + User warnings related to pandas operations + that only the user has control over. These + are configured to be printed once and only + once using a warning filter. + """ + + pass + + +# Configure user-pandas warnings to print only once +warnings.simplefilter("once", PandasUserOnceWarnings) + + def chunk_helper( lst: pandas.DataFrame, n: int ) -> Iterator[tuple[int, pandas.DataFrame]]: @@ -397,7 +412,7 @@ def write_pandas( f"Pandas Dataframe has non-standard index of type {str(type(df.index))} which will not be written." f" Consider changing the index to pd.RangeIndex(start=0,...,step=1) or " f"call reset_index() to keep index as column(s)", - UserWarning, + PandasUserOnceWarnings, stacklevel=2, ) @@ -411,7 +426,7 @@ def write_pandas( f"'{use_logical_type=}'. This can result in dateimes " "being incorrectly written to Snowflake. Consider setting " "'use_logical_type = True'", - UserWarning, + PandasUserOnceWarnings, stacklevel=2, )