From f4e0d00866fc56613a269b637723d4eb30f3655a Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Fri, 7 Jun 2024 13:33:22 +0300 Subject: [PATCH] Add CurrentPandasWarning --- pandas/_libs/tslibs/timestamps.pyx | 6 +-- pandas/core/generic.py | 8 ++-- pandas/core/groupby/generic.py | 4 +- pandas/core/indexes/accessors.py | 6 +-- pandas/core/internals/api.py | 4 +- pandas/core/reshape/concat.py | 4 +- pandas/io/feather_format.py | 4 +- pandas/io/parquet.py | 6 +-- pandas/io/parsers/arrow_parser_wrapper.py | 4 +- .../tests/copy_view/test_copy_deprecation.py | 20 ++++----- pandas/tests/extension/test_arrow.py | 6 +-- .../tests/frame/methods/test_reindex_like.py | 6 +-- pandas/tests/groupby/test_all_methods.py | 6 +-- pandas/tests/groupby/test_apply.py | 4 +- pandas/tests/groupby/test_categorical.py | 8 ++-- pandas/tests/groupby/test_groupby_dropna.py | 6 +-- pandas/tests/groupby/test_numeric_only.py | 6 +-- pandas/tests/groupby/test_raises.py | 4 +- .../tests/groupby/transform/test_transform.py | 6 +-- pandas/tests/io/formats/test_to_markdown.py | 4 +- pandas/tests/io/formats/test_to_string.py | 4 +- .../tests/io/json/test_json_table_schema.py | 4 +- pandas/tests/io/json/test_pandas.py | 44 +++++++++---------- pandas/tests/io/test_gcs.py | 4 +- pandas/tests/resample/test_datetime_index.py | 4 +- .../scalar/timestamp/test_constructors.py | 6 +-- .../tests/scalar/timestamp/test_timestamp.py | 8 ++-- .../series/accessors/test_cat_accessor.py | 4 +- .../series/accessors/test_dt_accessor.py | 4 +- .../tests/series/methods/test_reindex_like.py | 10 ++--- .../util/test_pandas_deprecation_warning.py | 4 +- pandas/util/_decorators.py | 8 ++-- pandas/util/_exceptions.py | 5 ++- 33 files changed, 116 insertions(+), 115 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 337e50233a045..7d021705d18e5 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -51,7 +51,7 @@ from pandas._libs.tslibs cimport ccalendar from pandas._libs.tslibs.base cimport ABCTimestamp from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + CurrentDeprecationWarning, find_stack_level, ) @@ -1536,7 +1536,7 @@ class Timestamp(_Timestamp): # GH#56680 "Timestamp.utcnow is deprecated and will be removed in a future " "version. Use Timestamp.now('UTC') instead.", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) return cls.now(UTC) @@ -1564,7 +1564,7 @@ class Timestamp(_Timestamp): # to match. GH#56680 "Timestamp.utcfromtimestamp is deprecated and will be removed in a " "future version. Use Timestamp.fromtimestamp(ts, 'UTC') instead.", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) return cls.fromtimestamp(ts, tz="UTC") diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d2841c8010629..3050214fdcbaa 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -98,7 +98,7 @@ doc, ) from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + CurrentDeprecationWarning, find_stack_level, ) from pandas.util._validators import ( @@ -2573,7 +2573,7 @@ def to_json( warnings.warn( "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead.", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) elif date_format == "epoch": @@ -2581,7 +2581,7 @@ def to_json( warnings.warn( "'epoch' date format is deprecated and will be removed in a future " "version, please use 'iso' date format instead.", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) @@ -4309,7 +4309,7 @@ def _check_copy_deprecation(copy): "version. Copy-on-Write is active in pandas since 3.0 which utilizes " "a lazy copy mechanism that defers copies until necessary. Use " ".copy() to make an eager copy if necessary.", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 0752b3c58495a..0ba5b95c70e72 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -34,7 +34,7 @@ doc, ) from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + CurrentDeprecationWarning, find_stack_level, ) @@ -2794,7 +2794,7 @@ def corrwith( """ warnings.warn( "DataFrameGroupBy.corrwith is deprecated", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) result = self._op_via_apply( diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 0e6c85f56ff82..ecb26e765cd4c 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -15,7 +15,7 @@ from pandas._libs import lib from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + CurrentDeprecationWarning, find_stack_level, ) @@ -221,7 +221,7 @@ def to_pytimedelta(self): "in a future version this will return a Series containing python " "datetime.timedelta objects instead of an ndarray. To retain the " "old behavior, call `np.array` on the result", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) return cast(ArrowExtensionArray, self._parent.array)._dt_to_pytimedelta() @@ -482,7 +482,7 @@ def to_pytimedelta(self) -> np.ndarray: "in a future version this will return a Series containing python " "datetime.timedelta objects instead of an ndarray. To retain the " "old behavior, call `np.array` on the result", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) return self._get_values().to_pytimedelta() diff --git a/pandas/core/internals/api.py b/pandas/core/internals/api.py index 4b73645139d47..4457ffdc98187 100644 --- a/pandas/core/internals/api.py +++ b/pandas/core/internals/api.py @@ -15,7 +15,7 @@ import numpy as np from pandas._libs.internals import BlockPlacement -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas.core.dtypes.common import pandas_dtype from pandas.core.dtypes.dtypes import ( @@ -94,7 +94,7 @@ def make_block( "make_block is deprecated and will be removed in a future version. " "Use pd.api.internals.create_dataframe_from_blocks or " "(recommended) higher-level public APIs instead.", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=2, ) diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 616b870f957b1..6b6aec8e3782e 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -19,7 +19,7 @@ from pandas._libs import lib from pandas.util._decorators import cache_readonly from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + CurrentDeprecationWarning, find_stack_level, ) @@ -385,7 +385,7 @@ def concat( "version. Copy-on-Write is active in pandas since 3.0 which utilizes " "a lazy copy mechanism that defers copies until necessary. Use " ".copy() to make an eager copy if necessary.", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/io/feather_format.py b/pandas/io/feather_format.py index 788d74928d7a4..fdb9c78151f88 100644 --- a/pandas/io/feather_format.py +++ b/pandas/io/feather_format.py @@ -13,7 +13,7 @@ from pandas._libs import lib from pandas.compat._optional import import_optional_dependency from pandas.util._decorators import doc -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas.util._validators import check_dtype_backend import pandas as pd @@ -137,7 +137,7 @@ def read_feather( warnings.filterwarnings( "ignore", "make_block is deprecated", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, ) return feather.read_feather( diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index 31f80b5108fda..5670040b52f12 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -21,7 +21,7 @@ from pandas.compat._optional import import_optional_dependency from pandas.errors import AbstractMethodError from pandas.util._decorators import doc -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas.util._validators import check_dtype_backend import pandas as pd @@ -279,7 +279,7 @@ def read( filterwarnings( "ignore", "make_block is deprecated", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, ) result = pa_table.to_pandas(**to_pandas_kwargs) @@ -398,7 +398,7 @@ def read( filterwarnings( "ignore", "make_block is deprecated", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, ) return parquet_file.to_pandas( columns=columns, filters=filters, **kwargs diff --git a/pandas/io/parsers/arrow_parser_wrapper.py b/pandas/io/parsers/arrow_parser_wrapper.py index c5b4adfd4b527..cec681ba40389 100644 --- a/pandas/io/parsers/arrow_parser_wrapper.py +++ b/pandas/io/parsers/arrow_parser_wrapper.py @@ -12,7 +12,7 @@ ParserWarning, ) from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + CurrentDeprecationWarning, find_stack_level, ) @@ -294,7 +294,7 @@ def read(self) -> DataFrame: warnings.filterwarnings( "ignore", "make_block is deprecated", - Pandas40DeprecationWarning, + CurrentDeprecationWarning, ) if dtype_backend == "pyarrow": frame = table.to_pandas(types_mapper=pd.ArrowDtype) diff --git a/pandas/tests/copy_view/test_copy_deprecation.py b/pandas/tests/copy_view/test_copy_deprecation.py index ec0e1d902c392..f5e1427172bba 100644 --- a/pandas/tests/copy_view/test_copy_deprecation.py +++ b/pandas/tests/copy_view/test_copy_deprecation.py @@ -1,6 +1,6 @@ import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas as pd from pandas import ( @@ -40,11 +40,11 @@ def test_copy_deprecation(meth, kwargs): df = df.set_index(["b", "c"]) if meth != "swaplevel": - with tm.assert_produces_warning(Pandas40DeprecationWarning, match="copy"): + with tm.assert_produces_warning(CurrentDeprecationWarning, match="copy"): getattr(df, meth)(copy=False, **kwargs) if meth != "transpose": - with tm.assert_produces_warning(Pandas40DeprecationWarning, match="copy"): + with tm.assert_produces_warning(CurrentDeprecationWarning, match="copy"): getattr(df.a, meth)(copy=False, **kwargs) @@ -52,22 +52,22 @@ def test_copy_deprecation_reindex_like_align(): df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}) # Somehow the stack level check is incorrect here with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + CurrentDeprecationWarning, match="copy", check_stacklevel=False ): df.reindex_like(df, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + CurrentDeprecationWarning, match="copy", check_stacklevel=False ): df.a.reindex_like(df.a, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + CurrentDeprecationWarning, match="copy", check_stacklevel=False ): df.align(df, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + CurrentDeprecationWarning, match="copy", check_stacklevel=False ): df.a.align(df.a, copy=False) @@ -76,16 +76,16 @@ def test_copy_deprecation_merge_concat(): df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + CurrentDeprecationWarning, match="copy", check_stacklevel=False ): df.merge(df, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + CurrentDeprecationWarning, match="copy", check_stacklevel=False ): merge(df, df, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + CurrentDeprecationWarning, match="copy", check_stacklevel=False ): concat([df, df], copy=False) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 8096975f8dc90..a58285d5ca2d1 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -43,7 +43,7 @@ pa_version_under13p0, pa_version_under14p0, ) -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas.util._test_decorators as td from pandas.core.dtypes.dtypes import ( @@ -2863,14 +2863,14 @@ def test_dt_to_pytimedelta(): ser = pd.Series(data, dtype=ArrowDtype(pa.duration("ns"))) msg = "The behavior of ArrowTemporalProperties.to_pytimedelta is deprecated" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): result = ser.dt.to_pytimedelta() expected = np.array(data, dtype=object) tm.assert_numpy_array_equal(result, expected) assert all(type(res) is timedelta for res in result) msg = "The behavior of TimedeltaProperties.to_pytimedelta is deprecated" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): expected = ser.astype("timedelta64[ns]").dt.to_pytimedelta() tm.assert_numpy_array_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_reindex_like.py b/pandas/tests/frame/methods/test_reindex_like.py index 3ab6752f8e6b5..0b12d82e457d2 100644 --- a/pandas/tests/frame/methods/test_reindex_like.py +++ b/pandas/tests/frame/methods/test_reindex_like.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas import DataFrame import pandas._testing as tm @@ -24,10 +24,10 @@ def test_reindex_like(self, float_frame): def test_reindex_like_methods(self, method, expected_values): df = DataFrame({"x": list(range(5))}) - with tm.assert_produces_warning(Pandas40DeprecationWarning): + with tm.assert_produces_warning(CurrentDeprecationWarning): result = df.reindex_like(df, method=method, tolerance=0) tm.assert_frame_equal(df, result) - with tm.assert_produces_warning(Pandas40DeprecationWarning): + with tm.assert_produces_warning(CurrentDeprecationWarning): result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0]) tm.assert_frame_equal(df, result) diff --git a/pandas/tests/groupby/test_all_methods.py b/pandas/tests/groupby/test_all_methods.py index 43689c76fd85a..199ce97e25650 100644 --- a/pandas/tests/groupby/test_all_methods.py +++ b/pandas/tests/groupby/test_all_methods.py @@ -13,7 +13,7 @@ import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas as pd from pandas import DataFrame @@ -28,7 +28,7 @@ def test_multiindex_group_all_columns_when_empty(groupby_func): method = getattr(gb, groupby_func) args = get_groupby_method_args(groupby_func, df) if groupby_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -74,7 +74,7 @@ def test_dup_labels_output_shape(groupby_func, idx): args = get_groupby_method_args(groupby_func, df) if groupby_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index a96463788ccda..3cc7833b8d919 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -6,7 +6,7 @@ import numpy as np import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas as pd from pandas import ( @@ -1200,7 +1200,7 @@ def test_apply_is_unchanged_when_other_methods_are_called_first(reduction_func): grp = df.groupby(by="a") args = get_groupby_method_args(reduction_func, df) if reduction_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 57776b8a78c67..3f177f34e7cf7 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas as pd from pandas import ( @@ -1476,7 +1476,7 @@ def test_dataframe_groupby_on_2_categoricals_when_observed_is_true(reduction_fun args = get_groupby_method_args(reduction_func, df) if reduction_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -1522,7 +1522,7 @@ def test_dataframe_groupby_on_2_categoricals_when_observed_is_false( return if reduction_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -1921,7 +1921,7 @@ def test_category_order_reducer( getattr(gb, reduction_func)(*args) return if reduction_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/groupby/test_groupby_dropna.py b/pandas/tests/groupby/test_groupby_dropna.py index f73440acedabc..71c706aba9f88 100644 --- a/pandas/tests/groupby/test_groupby_dropna.py +++ b/pandas/tests/groupby/test_groupby_dropna.py @@ -2,7 +2,7 @@ import pytest from pandas.compat.pyarrow import pa_version_under10p1 -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas.core.dtypes.missing import na_value_for_dtype @@ -545,7 +545,7 @@ def test_categorical_reducers(reduction_func, observed, sort, as_index, index_ki gb_filled = df_filled.groupby(keys, observed=observed, sort=sort, as_index=True) if reduction_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -576,7 +576,7 @@ def test_categorical_reducers(reduction_func, observed, sort, as_index, index_ki expected = expected["size"].rename(None) if reduction_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/groupby/test_numeric_only.py b/pandas/tests/groupby/test_numeric_only.py index f3e193be23a74..fe9d863408a3c 100644 --- a/pandas/tests/groupby/test_numeric_only.py +++ b/pandas/tests/groupby/test_numeric_only.py @@ -3,7 +3,7 @@ import pytest from pandas._libs import lib -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas as pd from pandas import ( @@ -258,7 +258,7 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys): if has_arg and numeric_only is True: # Cases where b does not appear in the result if kernel == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -305,7 +305,7 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys): msg = "'>' not supported between instances of 'type' and 'type'" with pytest.raises(exception, match=msg): if kernel == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/groupby/test_raises.py b/pandas/tests/groupby/test_raises.py index 97ab494c58599..a1d3e05981e7c 100644 --- a/pandas/tests/groupby/test_raises.py +++ b/pandas/tests/groupby/test_raises.py @@ -8,7 +8,7 @@ import numpy as np import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas import ( Categorical, @@ -87,7 +87,7 @@ def df_with_cat_col(): def _call_and_check(klass, msg, how, gb, groupby_func, args, warn_msg=""): - warn_klass = None if warn_msg == "" else Pandas40DeprecationWarning + warn_klass = None if warn_msg == "" else CurrentDeprecationWarning with tm.assert_produces_warning(warn_klass, match=warn_msg, check_stacklevel=False): if klass is None: if how == "method": diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index 45471fcc5bc8b..608cf6b8028a9 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -4,7 +4,7 @@ import pytest from pandas._libs import lib -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas.core.dtypes.common import ensure_platform_int @@ -1106,7 +1106,7 @@ def test_transform_agg_by_name(request, reduction_func, frame_or_series): args = get_groupby_method_args(reduction_func, obj) if func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -1477,7 +1477,7 @@ def test_as_index_no_change(keys, df, groupby_func): gb_as_index_true = df.groupby(keys, as_index=True) gb_as_index_false = df.groupby(keys, as_index=False) if groupby_func == "corrwith": - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/io/formats/test_to_markdown.py b/pandas/tests/io/formats/test_to_markdown.py index 96661d7948ba0..57018bb7229b0 100644 --- a/pandas/tests/io/formats/test_to_markdown.py +++ b/pandas/tests/io/formats/test_to_markdown.py @@ -2,7 +2,7 @@ import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas as pd import pandas._testing as tm @@ -17,7 +17,7 @@ def test_keyword_deprecation(): "except for the argument 'buf' will be keyword-only." ) s = pd.Series() - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): s.to_markdown(None, "wt") diff --git a/pandas/tests/io/formats/test_to_string.py b/pandas/tests/io/formats/test_to_string.py index d59355fa8a364..9d2ad482b50bb 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -12,7 +12,7 @@ from pandas._config import using_pyarrow_string_dtype -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas import ( CategoricalIndex, @@ -44,7 +44,7 @@ def test_keyword_deprecation(self): "except for the argument 'buf' will be keyword-only." ) s = Series(["a", "b"]) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): s.to_string(None, "NaN") def test_to_string_masked_ea_with_formatter(self): diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 18c1d6bd395ce..d45b71cded33e 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -7,7 +7,7 @@ import numpy as np import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas.core.dtypes.dtypes import ( CategoricalDtype, @@ -463,7 +463,7 @@ def test_date_format_raises(self, df_table): ) with pytest.raises(ValueError, match=error_msg): with tm.assert_produces_warning( - Pandas40DeprecationWarning, match=warning_msg + CurrentDeprecationWarning, match=warning_msg ): df_table.to_json(orient="table", date_format="epoch") diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 2839097294523..356d739805772 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -13,7 +13,7 @@ from pandas._config import using_pyarrow_string_dtype from pandas.compat import IS64 -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas.util._test_decorators as td import pandas as pd @@ -149,7 +149,7 @@ def test_frame_non_unique_columns(self, orient, data, request): "in a future version, please use 'iso' date format instead." ) if df.iloc[:, 0].dtype == "datetime64[s]": - expected_warning = Pandas40DeprecationWarning + expected_warning = CurrentDeprecationWarning with tm.assert_produces_warning(expected_warning, match=msg): result = read_json( @@ -781,7 +781,7 @@ def test_series_with_dtype_datetime(self, dtype, expected): "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): data = StringIO(s.to_json()) result = read_json(data, typ="series", dtype=dtype) tm.assert_series_equal(result, expected) @@ -832,13 +832,13 @@ def test_convert_dates(self, datetime_series, datetime_frame): "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): json = StringIO(df.to_json()) result = read_json(json) tm.assert_frame_equal(result, df) df["foo"] = 1.0 - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): json = StringIO(df.to_json(date_unit="ns")) result = read_json(json, convert_dates=False) @@ -849,7 +849,7 @@ def test_convert_dates(self, datetime_series, datetime_frame): # series ts = Series(Timestamp("20130101").as_unit("ns"), index=datetime_series.index) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): json = StringIO(ts.to_json()) result = read_json(json, typ="series") tm.assert_series_equal(result, ts) @@ -871,7 +871,7 @@ def test_date_index_and_values(self, date_format, as_object, date_typ): expected_warning = None if date_format == "epoch": expected = '{"1577836800000":1577836800000,"null":null}' - expected_warning = Pandas40DeprecationWarning + expected_warning = CurrentDeprecationWarning else: expected = ( '{"2020-01-01T00:00:00.000":"2020-01-01T00:00:00.000","null":null}' @@ -985,7 +985,7 @@ def test_date_unit(self, unit, datetime_frame): "'epoch' date format is deprecated and will be removed in a future " "version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): json = df.to_json(date_format="epoch", date_unit=unit) # force date unit @@ -1005,13 +1005,13 @@ def test_date_unit(self, unit, datetime_frame): DataFrame( {"A": ["a", "b", "c"], "B": pd.to_timedelta(np.arange(3), unit="D")} ), - Pandas40DeprecationWarning, + CurrentDeprecationWarning, ), ( DataFrame( {"A": pd.to_datetime(["2020-01-01", "2020-02-01", "2020-03-01"])} ), - Pandas40DeprecationWarning, + CurrentDeprecationWarning, ), ], ) @@ -1097,7 +1097,7 @@ def test_doc_example(self): "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): json = StringIO(dfj2.to_json()) result = read_json(json, dtype={"ints": np.int64, "bools": np.bool_}) tm.assert_frame_equal(result, result) @@ -1139,20 +1139,20 @@ def test_timedelta(self): "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): result = read_json(StringIO(ser.to_json()), typ="series").apply(converter) tm.assert_series_equal(result, ser) ser = Series([timedelta(23), timedelta(seconds=5)], index=Index([0, 1])) assert ser.dtype == "timedelta64[ns]" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): result = read_json(StringIO(ser.to_json()), typ="series").apply(converter) tm.assert_series_equal(result, ser) frame = DataFrame([timedelta(23), timedelta(seconds=5)]) assert frame[0].dtype == "timedelta64[ns]" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): json = frame.to_json() tm.assert_frame_equal(frame, read_json(StringIO(json)).apply(converter)) @@ -1168,7 +1168,7 @@ def test_timedelta2(self): "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): data = StringIO(frame.to_json(date_unit="ns")) result = read_json(data) result["a"] = pd.to_timedelta(result.a, unit="ns") @@ -1203,7 +1203,7 @@ def test_timedelta_to_json(self, as_object, date_format, timedelta_typ): '{"P1DT0H0M0S":"P1DT0H0M0S","P2DT0H0M0S":"P2DT0H0M0S","null":null}' ) else: - expected_warning = Pandas40DeprecationWarning + expected_warning = CurrentDeprecationWarning expected = '{"86400000":86400000,"172800000":172800000,"null":null}' if as_object: @@ -1222,7 +1222,7 @@ def test_timedelta_to_json(self, as_object, date_format, timedelta_typ): def test_timedelta_to_json_fractional_precision(self, as_object, timedelta_typ): data = [timedelta_typ(milliseconds=42)] ser = Series(data, index=data) - warn = Pandas40DeprecationWarning + warn = CurrentDeprecationWarning if as_object: ser = ser.astype(object) warn = None @@ -1318,13 +1318,13 @@ def test_datetime_tz(self): "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): expected = df_naive.to_json() assert expected == df.to_json() stz = Series(tz_range) s_naive = Series(tz_naive) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): assert stz.to_json() == s_naive.to_json() def test_sparse(self): @@ -1594,7 +1594,7 @@ def test_to_json_from_json_columns_dtypes(self, orient): "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): dfjson = expected.to_json(orient=orient) result = read_json( @@ -1788,7 +1788,7 @@ def test_timedelta_as_label(self, date_format, key): expected_warning = None if date_format == "epoch": - expected_warning = Pandas40DeprecationWarning + expected_warning = CurrentDeprecationWarning msg = ( "'epoch' date format is deprecated and will be removed in a future " @@ -2033,7 +2033,7 @@ def test_json_pandas_nulls(self, nulls_fixture, request): "in a future version, please use 'iso' date format instead." ) if nulls_fixture is pd.NaT: - expected_warning = Pandas40DeprecationWarning + expected_warning = CurrentDeprecationWarning with tm.assert_produces_warning(expected_warning, match=msg): result = DataFrame([[nulls_fixture]]).to_json() diff --git a/pandas/tests/io/test_gcs.py b/pandas/tests/io/test_gcs.py index e4de725ead5c6..3a4199fdaef14 100644 --- a/pandas/tests/io/test_gcs.py +++ b/pandas/tests/io/test_gcs.py @@ -7,7 +7,7 @@ import numpy as np import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas import ( DataFrame, @@ -84,7 +84,7 @@ def test_to_read_gcs(gcs_buffer, format, monkeypatch, capsys): "The default 'epoch' date format is deprecated and will be removed " "in a future version, please use 'iso' date format instead." ) - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): df1.to_json(path) df2 = read_json(path, convert_dates=["dt"]) elif format == "parquet": diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 387830bc6bb2e..8d520ed2132ed 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -8,7 +8,7 @@ from pandas._libs import lib from pandas._typing import DatetimeNaTType from pandas.compat import is_platform_windows -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas.util._test_decorators as td import pandas as pd @@ -1301,7 +1301,7 @@ def test_resample_consistency(unit): s10 = s.reindex(index=i10, method="bfill") s10_2 = s.reindex(index=i10, method="bfill", limit=2) - with tm.assert_produces_warning(Pandas40DeprecationWarning): + with tm.assert_produces_warning(CurrentDeprecationWarning): rl = s.reindex_like(s10, method="bfill", limit=2) r10_2 = s.resample("10Min").bfill(limit=2) r10 = s.resample("10Min").bfill() diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 33779bb4c0740..eee292790fec9 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -20,7 +20,7 @@ from pandas._libs.tslibs.dtypes import NpyDatetimeUnit from pandas.compat import PY310 from pandas.errors import OutOfBoundsDatetime -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas import ( NA, @@ -333,13 +333,13 @@ class TestTimestampClassMethodConstructors: def test_utcnow_deprecated(self): # GH#56680 msg = "Timestamp.utcnow is deprecated" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): Timestamp.utcnow() def test_utcfromtimestamp_deprecated(self): # GH#56680 msg = "Timestamp.utcfromtimestamp is deprecated" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): Timestamp.utcfromtimestamp(43) def test_constructor_strptime(self): diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index ba21f7eb6dd69..80925aa9f4289 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -31,7 +31,7 @@ tz_compare, ) from pandas.compat import IS64 -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas import ( NaT, @@ -270,7 +270,7 @@ def test_disallow_setting_tz(self, tz): def test_default_to_stdlib_utc(self): msg = "Timestamp.utcnow is deprecated" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): assert Timestamp.utcnow().tz is timezone.utc assert Timestamp.now("UTC").tz is timezone.utc assert Timestamp("2016-01-01", tz="UTC").tz is timezone.utc @@ -315,13 +315,13 @@ def compare(x, y): compare(Timestamp.now("UTC"), datetime.now(pytz.timezone("UTC"))) compare(Timestamp.now("UTC"), datetime.now(tzutc())) msg = "Timestamp.utcnow is deprecated" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): compare(Timestamp.utcnow(), datetime.now(timezone.utc)) compare(Timestamp.today(), datetime.today()) current_time = calendar.timegm(datetime.now().utctimetuple()) msg = "Timestamp.utcfromtimestamp is deprecated" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): ts_utc = Timestamp.utcfromtimestamp(current_time) assert ts_utc.timestamp() == current_time compare( diff --git a/pandas/tests/series/accessors/test_cat_accessor.py b/pandas/tests/series/accessors/test_cat_accessor.py index 4c9034d645844..c60bb51cf0234 100644 --- a/pandas/tests/series/accessors/test_cat_accessor.py +++ b/pandas/tests/series/accessors/test_cat_accessor.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas import ( Categorical, @@ -204,7 +204,7 @@ def test_dt_accessor_api_for_categorical(self, idx): warn_cls.append(UserWarning) elif func == "to_pytimedelta": # GH 57463 - warn_cls.append(Pandas40DeprecationWarning) + warn_cls.append(CurrentDeprecationWarning) if warn_cls: warn_cls = tuple(warn_cls) else: diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index 2dc27e726a6c4..4e60e9e96930e 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -12,7 +12,7 @@ import pytz from pandas._libs.tslibs.timezones import maybe_get_tz -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas.core.dtypes.common import ( is_integer_dtype, @@ -194,7 +194,7 @@ def test_dt_namespace_accessor_timedelta(self): tm.assert_index_equal(result.index, ser.index) msg = "The behavior of TimedeltaProperties.to_pytimedelta is deprecated" - with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): + with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): result = ser.dt.to_pytimedelta() assert isinstance(result, np.ndarray) assert result.dtype == object diff --git a/pandas/tests/series/methods/test_reindex_like.py b/pandas/tests/series/methods/test_reindex_like.py index 81311fbe14f18..4e462cdf5c1be 100644 --- a/pandas/tests/series/methods/test_reindex_like.py +++ b/pandas/tests/series/methods/test_reindex_like.py @@ -2,7 +2,7 @@ import numpy as np -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning from pandas import Series import pandas._testing as tm @@ -22,7 +22,7 @@ def test_reindex_like(datetime_series): series1 = Series([5, None, None], [day1, day2, day3]) series2 = Series([None, None], [day1, day3]) - with tm.assert_produces_warning(Pandas40DeprecationWarning): + with tm.assert_produces_warning(CurrentDeprecationWarning): result = series1.reindex_like(series2, method="pad") expected = Series([5, np.nan], index=[day1, day3]) tm.assert_series_equal(result, expected) @@ -35,13 +35,13 @@ def test_reindex_like_nearest(): other = ser.reindex(target, method="nearest") expected = Series(np.around(target).astype("int64"), target) - with tm.assert_produces_warning(Pandas40DeprecationWarning): + with tm.assert_produces_warning(CurrentDeprecationWarning): result = ser.reindex_like(other, method="nearest") tm.assert_series_equal(expected, result) - with tm.assert_produces_warning(Pandas40DeprecationWarning): + with tm.assert_produces_warning(CurrentDeprecationWarning): result = ser.reindex_like(other, method="nearest", tolerance=1) tm.assert_series_equal(expected, result) - with tm.assert_produces_warning(Pandas40DeprecationWarning): + with tm.assert_produces_warning(CurrentDeprecationWarning): result = ser.reindex_like(other, method="nearest", tolerance=[1, 2, 3, 4]) tm.assert_series_equal(expected, result) diff --git a/pandas/tests/util/test_pandas_deprecation_warning.py b/pandas/tests/util/test_pandas_deprecation_warning.py index 1a813b6eb4afb..f8a16e6ed8961 100644 --- a/pandas/tests/util/test_pandas_deprecation_warning.py +++ b/pandas/tests/util/test_pandas_deprecation_warning.py @@ -1,13 +1,13 @@ import warnings from pandas.util._decorators import deprecate_kwarg -from pandas.util._exceptions import Pandas40DeprecationWarning +from pandas.util._exceptions import CurrentDeprecationWarning import pandas._testing as tm def f1(): - warnings.warn("f1", Pandas40DeprecationWarning) + warnings.warn("f1", CurrentDeprecationWarning) def test_function_warns_pandas_deprecation_warning(): diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index faaaf10d160ac..33ab5b22557fc 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -17,7 +17,7 @@ T, ) from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + CurrentDeprecationWarning, find_stack_level, ) @@ -61,7 +61,7 @@ def deprecate( Default is '{name} is deprecated. Use {alt_name} instead.' """ alt_name = alt_name or alternative.__name__ - klass = klass or Pandas40DeprecationWarning + klass = klass or CurrentDeprecationWarning warning_msg = msg or f"{name} is deprecated, use {alt_name} instead." @wraps(alternative) @@ -173,7 +173,7 @@ def deprecate_kwarg( raise TypeError( "mapping from old to new argument values must be dict or callable!" ) - klass = klass or Pandas40DeprecationWarning + klass = klass or CurrentDeprecationWarning def _deprecate_kwarg(func: F) -> F: @wraps(func) @@ -300,7 +300,7 @@ def deprecate_nonkeyword_arguments( klass : Warning, optional The warning class to use. """ - klass = klass or Pandas40DeprecationWarning + klass = klass or CurrentDeprecationWarning def decorate(func): old_sig = inspect.signature(func) diff --git a/pandas/util/_exceptions.py b/pandas/util/_exceptions.py index 6f3cda76f7fd2..4f3ec22d89fe1 100644 --- a/pandas/util/_exceptions.py +++ b/pandas/util/_exceptions.py @@ -11,8 +11,9 @@ from collections.abc import Generator from types import FrameType -Pandas40DeprecationWarning = DeprecationWarning -Pandas50DeprecationWarning = DeprecationWarning +Pandas4DeprecationWarning = DeprecationWarning +Pandas5DeprecationWarning = DeprecationWarning +CurrentDeprecationWarning = Pandas4DeprecationWarning @contextlib.contextmanager