From bdc86175e31a527f17262c1e0a22d0eafba2a911 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Date: Sat, 6 Apr 2024 00:33:14 +0300 Subject: [PATCH 01/17] Initial concept --- doc/source/whatsnew/v3.0.0.rst | 5 +++++ pandas/_libs/tslibs/timestamps.pyx | 9 ++++++--- pandas/core/generic.py | 7 +++++-- pandas/core/reshape/concat.py | 7 +++++-- pandas/core/series.py | 15 +++++++++++--- .../tests/copy_view/test_copy_deprecation.py | 20 ++++++++++--------- pandas/tests/copy_view/test_methods.py | 8 ++++++-- pandas/tests/io/formats/test_to_markdown.py | 4 +++- pandas/tests/io/formats/test_to_string.py | 4 +++- .../scalar/timestamp/test_constructors.py | 5 +++-- .../tests/scalar/timestamp/test_timestamp.py | 7 ++++--- pandas/util/_decorators.py | 20 +++++++++++++------ pandas/util/_exceptions.py | 2 ++ 13 files changed, 79 insertions(+), 34 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index bb1e0b33c2ab8..0ad067dc73f96 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -24,6 +24,10 @@ enhancement1 enhancement2 ^^^^^^^^^^^^ +New Deprecation Policy +^^^^^^^^^^^^^^^^^^^^^^ +pandas 3.0.0 introduces a new 3-stage deprecation policy: first raising ``DeprecationWarning`` when using deprecated functionality, then switching to ``FutureWarning`` in the next major version for broader visibility, and then removal of the deprecated functionalities in the version after. + .. _whatsnew_300.enhancements.other: Other enhancements @@ -159,6 +163,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ + Copy keyword ^^^^^^^^^^^^ diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index d4cd90613ca5b..c93d532b565d6 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -50,7 +50,10 @@ import datetime as dt from pandas._libs.tslibs cimport ccalendar from pandas._libs.tslibs.base cimport ABCTimestamp -from pandas.util._exceptions import find_stack_level +from pandas.util._exceptions import ( + Pandas30DeprecationWarning, + find_stack_level, +) from pandas._libs.tslibs.conversion cimport ( _TSObject, @@ -1423,7 +1426,7 @@ class Timestamp(_Timestamp): # GH#56680 "Timestamp.utcnow is deprecated and will be removed in a future " "version. Use Timestamp.now('UTC') instead.", - FutureWarning, + Pandas30DeprecationWarning, stacklevel=find_stack_level(), ) return cls.now(UTC) @@ -1451,7 +1454,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.", - FutureWarning, + Pandas30DeprecationWarning, stacklevel=find_stack_level(), ) return cls.fromtimestamp(ts, tz="UTC") diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 99462917599e1..ee3cafec586a1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -94,7 +94,10 @@ ) from pandas.errors.cow import _chained_assignment_method_msg from pandas.util._decorators import doc -from pandas.util._exceptions import find_stack_level +from pandas.util._exceptions import ( + Pandas30DeprecationWarning, + find_stack_level, +) from pandas.util._validators import ( check_dtype_backend, validate_ascending, @@ -4255,7 +4258,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.", - DeprecationWarning, + Pandas30DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index d17e5b475ae57..eaedd6f160c04 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -18,7 +18,10 @@ from pandas._libs import lib from pandas.util._decorators import cache_readonly -from pandas.util._exceptions import find_stack_level +from pandas.util._exceptions import ( + Pandas30DeprecationWarning, + find_stack_level, +) from pandas.core.dtypes.common import is_bool from pandas.core.dtypes.concat import concat_compat @@ -382,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.", - DeprecationWarning, + Pandas30DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/series.py b/pandas/core/series.py index 967aea15fff60..c616e322644e2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -49,7 +49,10 @@ deprecate_nonkeyword_arguments, doc, ) -from pandas.util._exceptions import find_stack_level +from pandas.util._exceptions import ( + Pandas30DeprecationWarning, + find_stack_level, +) from pandas.util._validators import ( validate_ascending, validate_bool_kwarg, @@ -1506,7 +1509,10 @@ def to_string( ) -> None: ... @deprecate_nonkeyword_arguments( - version="3.0.0", allowed_args=["self", "buf"], name="to_string" + version="3.0.0", + allowed_args=["self", "buf"], + name="to_string", + klass=Pandas30DeprecationWarning, ) def to_string( self, @@ -1657,7 +1663,10 @@ def to_markdown( ), ) @deprecate_nonkeyword_arguments( - version="3.0.0", allowed_args=["self", "buf"], name="to_markdown" + version="3.0.0", + allowed_args=["self", "buf"], + name="to_markdown", + klass=Pandas30DeprecationWarning, ) def to_markdown( self, diff --git a/pandas/tests/copy_view/test_copy_deprecation.py b/pandas/tests/copy_view/test_copy_deprecation.py index 8ee37213b92ab..09ab38a306d2b 100644 --- a/pandas/tests/copy_view/test_copy_deprecation.py +++ b/pandas/tests/copy_view/test_copy_deprecation.py @@ -1,5 +1,7 @@ import pytest +from pandas.util._exceptions import Pandas30DeprecationWarning + import pandas as pd from pandas import ( concat, @@ -38,11 +40,11 @@ def test_copy_deprecation(meth, kwargs): df = df.set_index(["b", "c"]) if meth != "swaplevel": - with tm.assert_produces_warning(DeprecationWarning, match="copy"): + with tm.assert_produces_warning(Pandas30DeprecationWarning, match="copy"): getattr(df, meth)(copy=False, **kwargs) if meth != "transpose": - with tm.assert_produces_warning(DeprecationWarning, match="copy"): + with tm.assert_produces_warning(Pandas30DeprecationWarning, match="copy"): getattr(df.a, meth)(copy=False, **kwargs) @@ -50,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( - DeprecationWarning, match="copy", check_stacklevel=False + Pandas30DeprecationWarning, match="copy", check_stacklevel=False ): df.reindex_like(df, copy=False) with tm.assert_produces_warning( - DeprecationWarning, match="copy", check_stacklevel=False + Pandas30DeprecationWarning, match="copy", check_stacklevel=False ): df.a.reindex_like(df.a, copy=False) with tm.assert_produces_warning( - DeprecationWarning, match="copy", check_stacklevel=False + Pandas30DeprecationWarning, match="copy", check_stacklevel=False ): df.align(df, copy=False) with tm.assert_produces_warning( - DeprecationWarning, match="copy", check_stacklevel=False + Pandas30DeprecationWarning, match="copy", check_stacklevel=False ): df.a.align(df.a, copy=False) @@ -74,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( - DeprecationWarning, match="copy", check_stacklevel=False + Pandas30DeprecationWarning, match="copy", check_stacklevel=False ): df.merge(df, copy=False) with tm.assert_produces_warning( - DeprecationWarning, match="copy", check_stacklevel=False + Pandas30DeprecationWarning, match="copy", check_stacklevel=False ): merge(df, df, copy=False) with tm.assert_produces_warning( - DeprecationWarning, match="copy", check_stacklevel=False + Pandas30DeprecationWarning, match="copy", check_stacklevel=False ): concat([df, df], copy=False) diff --git a/pandas/tests/copy_view/test_methods.py b/pandas/tests/copy_view/test_methods.py index 3712a74fe54ed..e36f370a27aa1 100644 --- a/pandas/tests/copy_view/test_methods.py +++ b/pandas/tests/copy_view/test_methods.py @@ -60,7 +60,9 @@ def test_copy_shallow(): assert np.shares_memory(get_array(df_copy, "c"), get_array(df, "c")) -@pytest.mark.filterwarnings("ignore::DeprecationWarning") +@pytest.mark.filterwarnings( + "ignore::pandas.util._exceptions.Pandas30DeprecationWarning" +) @pytest.mark.parametrize("copy", [True, None, False]) @pytest.mark.parametrize( "method", @@ -117,7 +119,9 @@ def test_methods_copy_keyword(request, method, copy): assert np.shares_memory(get_array(df2, "a"), get_array(df, "a")) -@pytest.mark.filterwarnings("ignore::DeprecationWarning") +@pytest.mark.filterwarnings( + "ignore::pandas.util._exceptions.Pandas30DeprecationWarning" +) @pytest.mark.parametrize("copy", [True, None, False]) @pytest.mark.parametrize( "method", diff --git a/pandas/tests/io/formats/test_to_markdown.py b/pandas/tests/io/formats/test_to_markdown.py index fffb1b9b9d2a4..1be1799013266 100644 --- a/pandas/tests/io/formats/test_to_markdown.py +++ b/pandas/tests/io/formats/test_to_markdown.py @@ -2,6 +2,8 @@ import pytest +from pandas.util._exceptions import Pandas30DeprecationWarning + import pandas as pd import pandas._testing as tm @@ -15,7 +17,7 @@ def test_keyword_deprecation(): "except for the argument 'buf' will be keyword-only." ) s = pd.Series() - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas30DeprecationWarning, 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 7c7069aa74eeb..a46c50c4eab3d 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -12,6 +12,8 @@ from pandas._config import using_pyarrow_string_dtype +from pandas.util._exceptions import Pandas30DeprecationWarning + from pandas import ( CategoricalIndex, DataFrame, @@ -42,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas30DeprecationWarning, match=msg): s.to_string(None, "NaN") def test_to_string_masked_ea_with_formatter(self): diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index bbda9d3ee7dce..536407f24cbf8 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -20,6 +20,7 @@ from pandas._libs.tslibs.dtypes import NpyDatetimeUnit from pandas.compat import PY310 from pandas.errors import OutOfBoundsDatetime +from pandas.util._exceptions import Pandas30DeprecationWarning from pandas import ( NA, @@ -332,13 +333,13 @@ class TestTimestampClassMethodConstructors: def test_utcnow_deprecated(self): # GH#56680 msg = "Timestamp.utcnow is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas30DeprecationWarning, match=msg): Timestamp.utcnow() def test_utcfromtimestamp_deprecated(self): # GH#56680 msg = "Timestamp.utcfromtimestamp is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas30DeprecationWarning, 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 ea970433464fc..daad14fe3f7a5 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -31,6 +31,7 @@ tz_compare, ) from pandas.compat import IS64 +from pandas.util._exceptions import Pandas30DeprecationWarning from pandas import ( NaT, @@ -269,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas30DeprecationWarning, 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 @@ -314,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas30DeprecationWarning, 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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas30DeprecationWarning, match=msg): ts_utc = Timestamp.utcfromtimestamp(current_time) assert ts_utc.timestamp() == current_time compare( diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index d287fa72d552d..f77865bccd5fb 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -101,6 +101,7 @@ def deprecate_kwarg( old_arg_name: str, new_arg_name: str | None, mapping: Mapping[Any, Any] | Callable[[Any], Any] | None = None, + klass: type[Warning] | None = None, stacklevel: int = 2, ) -> Callable[[F], F]: """ @@ -109,7 +110,7 @@ def deprecate_kwarg( Parameters ---------- old_arg_name : str - Name of argument in function to deprecate + Name of argument in function to deprecate. new_arg_name : str or None Name of preferred argument in function. Use None to raise warning that ``old_arg_name`` keyword is deprecated. @@ -117,6 +118,8 @@ def deprecate_kwarg( If mapping is present, use it to translate old arguments to new arguments. A callable must do its own value checking; values not found in a dict will be forwarded unchanged. + klass : Warning, default FutureWarning + stacklevel : int, default 2 Examples -------- @@ -151,20 +154,21 @@ def deprecate_kwarg( ... print(cols) >>> f(cols="should raise warning") # doctest: +SKIP FutureWarning: the 'cols' keyword is deprecated and will be removed in a - future version please takes steps to stop use of 'cols' + future version. Please take steps to stop the use of 'cols' should raise warning >>> f(another_param="should not raise warning") # doctest: +SKIP should not raise warning >>> f(cols="should raise warning", another_param="") # doctest: +SKIP FutureWarning: the 'cols' keyword is deprecated and will be removed in a - future version please takes steps to stop use of 'cols' + future version. Please take steps to stop the use of 'cols' should raise warning """ if mapping is not None and not hasattr(mapping, "get") and not callable(mapping): raise TypeError( "mapping from old to new argument values must be dict or callable!" ) + klass = klass or FutureWarning def _deprecate_kwarg(func: F) -> F: @wraps(func) @@ -178,7 +182,7 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]: "will be removed in a future version. Please take " f"steps to stop the use of {old_arg_name!r}" ) - warnings.warn(msg, FutureWarning, stacklevel=stacklevel) + warnings.warn(msg, klass, stacklevel=stacklevel) kwargs[old_arg_name] = old_arg_value return func(*args, **kwargs) @@ -199,7 +203,7 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]: f"use {new_arg_name!r} instead." ) - warnings.warn(msg, FutureWarning, stacklevel=stacklevel) + warnings.warn(msg, klass, stacklevel=stacklevel) if kwargs.get(new_arg_name) is not None: msg = ( f"Can only specify {old_arg_name!r} " @@ -264,6 +268,7 @@ def deprecate_nonkeyword_arguments( version: str | None, allowed_args: list[str] | None = None, name: str | None = None, + klass: type[Warning] | None = None, ) -> Callable[[F], F]: """ Decorator to deprecate a use of non-keyword arguments of a function. @@ -286,7 +291,10 @@ def deprecate_nonkeyword_arguments( The specific name of the function to show in the warning message. If None, then the Qualified name of the function is used. + + klass : Warning, default FutureWarning """ + klass = klass or FutureWarning def decorate(func): old_sig = inspect.signature(func) @@ -324,7 +332,7 @@ def wrapper(*args, **kwargs): if len(args) > num_allow_args: warnings.warn( msg.format(arguments=_format_argument_list(allow_args)), - FutureWarning, + klass, stacklevel=find_stack_level(), ) return func(*args, **kwargs) diff --git a/pandas/util/_exceptions.py b/pandas/util/_exceptions.py index 5f50838d37315..1636b4b5c006f 100644 --- a/pandas/util/_exceptions.py +++ b/pandas/util/_exceptions.py @@ -11,6 +11,8 @@ from collections.abc import Generator from types import FrameType +Pandas30DeprecationWarning = DeprecationWarning + @contextlib.contextmanager def rewrite_exception(old_name: str, new_name: str) -> Generator[None, None, None]: From a586153c26b2680e9f1cbb7efb3eaf199c374543 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Date: Sat, 6 Apr 2024 02:01:40 +0300 Subject: [PATCH 02/17] Use version of removal for warning name --- doc/source/whatsnew/v3.0.0.rst | 2 +- pandas/_libs/tslibs/timestamps.pyx | 6 +++--- pandas/core/generic.py | 4 ++-- pandas/core/reshape/concat.py | 4 ++-- pandas/core/series.py | 6 +++--- .../tests/copy_view/test_copy_deprecation.py | 20 +++++++++---------- pandas/tests/copy_view/test_methods.py | 4 ++-- pandas/tests/io/formats/test_to_markdown.py | 4 ++-- pandas/tests/io/formats/test_to_string.py | 4 ++-- .../scalar/timestamp/test_constructors.py | 6 +++--- .../tests/scalar/timestamp/test_timestamp.py | 8 ++++---- pandas/util/_exceptions.py | 2 +- 12 files changed, 35 insertions(+), 35 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 0ad067dc73f96..60b894990a6ed 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -26,7 +26,7 @@ enhancement2 New Deprecation Policy ^^^^^^^^^^^^^^^^^^^^^^ -pandas 3.0.0 introduces a new 3-stage deprecation policy: first raising ``DeprecationWarning`` when using deprecated functionality, then switching to ``FutureWarning`` in the next major version for broader visibility, and then removal of the deprecated functionalities in the version after. +pandas 3.0.0 introduces a new 3-stage deprecation policy: using ``DeprecationWarning`` initially, then switching to ``FutureWarning`` for broader visibility in the last minor version before the next major release , and then removal of the deprecated functionalities in the major release. .. _whatsnew_300.enhancements.other: diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index c93d532b565d6..8c00338a3a5b0 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 ( - Pandas30DeprecationWarning, + Pandas40DeprecationWarning, find_stack_level, ) @@ -1426,7 +1426,7 @@ class Timestamp(_Timestamp): # GH#56680 "Timestamp.utcnow is deprecated and will be removed in a future " "version. Use Timestamp.now('UTC') instead.", - Pandas30DeprecationWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) return cls.now(UTC) @@ -1454,7 +1454,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.", - Pandas30DeprecationWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) return cls.fromtimestamp(ts, tz="UTC") diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ee3cafec586a1..b8f3dd8083541 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -95,7 +95,7 @@ from pandas.errors.cow import _chained_assignment_method_msg from pandas.util._decorators import doc from pandas.util._exceptions import ( - Pandas30DeprecationWarning, + Pandas40DeprecationWarning, find_stack_level, ) from pandas.util._validators import ( @@ -4258,7 +4258,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.", - Pandas30DeprecationWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index eaedd6f160c04..d7f62caecad5a 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 ( - Pandas30DeprecationWarning, + Pandas40DeprecationWarning, 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.", - Pandas30DeprecationWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/series.py b/pandas/core/series.py index c616e322644e2..2397266748b21 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -50,7 +50,7 @@ doc, ) from pandas.util._exceptions import ( - Pandas30DeprecationWarning, + Pandas40DeprecationWarning, find_stack_level, ) from pandas.util._validators import ( @@ -1512,7 +1512,7 @@ def to_string( version="3.0.0", allowed_args=["self", "buf"], name="to_string", - klass=Pandas30DeprecationWarning, + klass=Pandas40DeprecationWarning, ) def to_string( self, @@ -1666,7 +1666,7 @@ def to_markdown( version="3.0.0", allowed_args=["self", "buf"], name="to_markdown", - klass=Pandas30DeprecationWarning, + klass=Pandas40DeprecationWarning, ) def to_markdown( self, diff --git a/pandas/tests/copy_view/test_copy_deprecation.py b/pandas/tests/copy_view/test_copy_deprecation.py index 09ab38a306d2b..ec0e1d902c392 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 Pandas30DeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(Pandas30DeprecationWarning, match="copy"): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match="copy"): getattr(df, meth)(copy=False, **kwargs) if meth != "transpose": - with tm.assert_produces_warning(Pandas30DeprecationWarning, match="copy"): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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( - Pandas30DeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): df.reindex_like(df, copy=False) with tm.assert_produces_warning( - Pandas30DeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): df.a.reindex_like(df.a, copy=False) with tm.assert_produces_warning( - Pandas30DeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): df.align(df, copy=False) with tm.assert_produces_warning( - Pandas30DeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, 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( - Pandas30DeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): df.merge(df, copy=False) with tm.assert_produces_warning( - Pandas30DeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): merge(df, df, copy=False) with tm.assert_produces_warning( - Pandas30DeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): concat([df, df], copy=False) diff --git a/pandas/tests/copy_view/test_methods.py b/pandas/tests/copy_view/test_methods.py index e36f370a27aa1..9e36f6c812948 100644 --- a/pandas/tests/copy_view/test_methods.py +++ b/pandas/tests/copy_view/test_methods.py @@ -61,7 +61,7 @@ def test_copy_shallow(): @pytest.mark.filterwarnings( - "ignore::pandas.util._exceptions.Pandas30DeprecationWarning" + "ignore::DeprecationWarning" ) @pytest.mark.parametrize("copy", [True, None, False]) @pytest.mark.parametrize( @@ -120,7 +120,7 @@ def test_methods_copy_keyword(request, method, copy): @pytest.mark.filterwarnings( - "ignore::pandas.util._exceptions.Pandas30DeprecationWarning" + "ignore::DeprecationWarning" ) @pytest.mark.parametrize("copy", [True, None, False]) @pytest.mark.parametrize( diff --git a/pandas/tests/io/formats/test_to_markdown.py b/pandas/tests/io/formats/test_to_markdown.py index 1be1799013266..96661d7948ba0 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 Pandas30DeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(Pandas30DeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 a46c50c4eab3d..d59355fa8a364 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 Pandas30DeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(Pandas30DeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): s.to_string(None, "NaN") def test_to_string_masked_ea_with_formatter(self): diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 536407f24cbf8..6e81211b26118 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 Pandas30DeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(Pandas30DeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): Timestamp.utcnow() def test_utcfromtimestamp_deprecated(self): # GH#56680 msg = "Timestamp.utcfromtimestamp is deprecated" - with tm.assert_produces_warning(Pandas30DeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 daad14fe3f7a5..f448bda9299c3 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 Pandas30DeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(Pandas30DeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(Pandas30DeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(Pandas30DeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): ts_utc = Timestamp.utcfromtimestamp(current_time) assert ts_utc.timestamp() == current_time compare( diff --git a/pandas/util/_exceptions.py b/pandas/util/_exceptions.py index 1636b4b5c006f..89361e63cb2eb 100644 --- a/pandas/util/_exceptions.py +++ b/pandas/util/_exceptions.py @@ -11,7 +11,7 @@ from collections.abc import Generator from types import FrameType -Pandas30DeprecationWarning = DeprecationWarning +Pandas40DeprecationWarning = DeprecationWarning @contextlib.contextmanager From 3f82398762d0a044e674258eef0a1dd79bd55612 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Date: Sat, 6 Apr 2024 02:04:26 +0300 Subject: [PATCH 03/17] Fix grammar --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 60b894990a6ed..47e623447078e 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -26,7 +26,7 @@ enhancement2 New Deprecation Policy ^^^^^^^^^^^^^^^^^^^^^^ -pandas 3.0.0 introduces a new 3-stage deprecation policy: using ``DeprecationWarning`` initially, then switching to ``FutureWarning`` for broader visibility in the last minor version before the next major release , and then removal of the deprecated functionalities in the major release. +pandas 3.0.0 introduces a new 3-stage deprecation policy: using ``DeprecationWarning`` initially, then switching to ``FutureWarning`` for broader visibility in the last minor version before the next major release, and then removal of the deprecated functionality in the major release. .. _whatsnew_300.enhancements.other: From 80239b5667cf4c2fead1f13127d046442948dfea Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Date: Sat, 6 Apr 2024 02:21:30 +0300 Subject: [PATCH 04/17] Change decorators default warning --- pandas/core/series.py | 15 +++------------ pandas/tests/copy_view/test_methods.py | 8 ++------ pandas/util/_decorators.py | 23 ++++++++++++++++------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 2397266748b21..967aea15fff60 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -49,10 +49,7 @@ deprecate_nonkeyword_arguments, doc, ) -from pandas.util._exceptions import ( - Pandas40DeprecationWarning, - find_stack_level, -) +from pandas.util._exceptions import find_stack_level from pandas.util._validators import ( validate_ascending, validate_bool_kwarg, @@ -1509,10 +1506,7 @@ def to_string( ) -> None: ... @deprecate_nonkeyword_arguments( - version="3.0.0", - allowed_args=["self", "buf"], - name="to_string", - klass=Pandas40DeprecationWarning, + version="3.0.0", allowed_args=["self", "buf"], name="to_string" ) def to_string( self, @@ -1663,10 +1657,7 @@ def to_markdown( ), ) @deprecate_nonkeyword_arguments( - version="3.0.0", - allowed_args=["self", "buf"], - name="to_markdown", - klass=Pandas40DeprecationWarning, + version="3.0.0", allowed_args=["self", "buf"], name="to_markdown" ) def to_markdown( self, diff --git a/pandas/tests/copy_view/test_methods.py b/pandas/tests/copy_view/test_methods.py index 9e36f6c812948..3712a74fe54ed 100644 --- a/pandas/tests/copy_view/test_methods.py +++ b/pandas/tests/copy_view/test_methods.py @@ -60,9 +60,7 @@ def test_copy_shallow(): assert np.shares_memory(get_array(df_copy, "c"), get_array(df, "c")) -@pytest.mark.filterwarnings( - "ignore::DeprecationWarning" -) +@pytest.mark.filterwarnings("ignore::DeprecationWarning") @pytest.mark.parametrize("copy", [True, None, False]) @pytest.mark.parametrize( "method", @@ -119,9 +117,7 @@ def test_methods_copy_keyword(request, method, copy): assert np.shares_memory(get_array(df2, "a"), get_array(df, "a")) -@pytest.mark.filterwarnings( - "ignore::DeprecationWarning" -) +@pytest.mark.filterwarnings("ignore::DeprecationWarning") @pytest.mark.parametrize("copy", [True, None, False]) @pytest.mark.parametrize( "method", diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index f77865bccd5fb..3d09cda63c546 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -16,7 +16,10 @@ F, T, ) -from pandas.util._exceptions import find_stack_level +from pandas.util._exceptions import ( + Pandas40DeprecationWarning, + find_stack_level, +) if TYPE_CHECKING: from collections.abc import Mapping @@ -50,14 +53,16 @@ def deprecate( Version of pandas in which the method has been deprecated. alt_name : str, optional Name to use in preference of alternative.__name__. - klass : Warning, default FutureWarning + klass : Warning, optional + The warning class to use. Defaults to FutureWarning in the + last minor version before a major release, otherwise DeprecationWarning. stacklevel : int, default 2 msg : str The message to display in the warning. Default is '{name} is deprecated. Use {alt_name} instead.' """ alt_name = alt_name or alternative.__name__ - klass = klass or FutureWarning + klass = klass or Pandas40DeprecationWarning warning_msg = msg or f"{name} is deprecated, use {alt_name} instead." @wraps(alternative) @@ -118,7 +123,9 @@ def deprecate_kwarg( If mapping is present, use it to translate old arguments to new arguments. A callable must do its own value checking; values not found in a dict will be forwarded unchanged. - klass : Warning, default FutureWarning + klass : Warning, optional + The warning class to use. Defaults to FutureWarning in the + last minor version before a major release, otherwise DeprecationWarning. stacklevel : int, default 2 Examples @@ -168,7 +175,7 @@ def deprecate_kwarg( raise TypeError( "mapping from old to new argument values must be dict or callable!" ) - klass = klass or FutureWarning + klass = klass or Pandas40DeprecationWarning def _deprecate_kwarg(func: F) -> F: @wraps(func) @@ -292,9 +299,11 @@ def deprecate_nonkeyword_arguments( message. If None, then the Qualified name of the function is used. - klass : Warning, default FutureWarning + klass : Warning, optional + The warning class to use. Defaults to FutureWarning in the + last minor version before a major release, otherwise DeprecationWarning. """ - klass = klass or FutureWarning + klass = klass or Pandas40DeprecationWarning def decorate(func): old_sig = inspect.signature(func) From 8d3debc9061fd83392f1b6a62c108f22663c2a36 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Date: Sat, 6 Apr 2024 03:15:02 +0300 Subject: [PATCH 05/17] Fix decorator tests --- pandas/tests/tools/test_to_datetime.py | 4 +++- pandas/tests/util/test_deprecate.py | 10 ++++++++-- pandas/tests/util/test_deprecate_kwarg.py | 8 ++++---- .../util/test_deprecate_nonkeyword_arguments.py | 12 +++++++----- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 7992b48a4b0cc..74a4f720dc1eb 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1006,7 +1006,9 @@ def test_to_datetime_today(self, tz): def test_to_datetime_today_now_unicode_bytes(self, arg): to_datetime([arg]) - @pytest.mark.filterwarnings("ignore:Timestamp.utcnow is deprecated:FutureWarning") + @pytest.mark.filterwarnings( + "ignore:Timestamp.utcnow is deprecated:DeprecationWarning" + ) @pytest.mark.parametrize( "format, expected_ds", [ diff --git a/pandas/tests/util/test_deprecate.py b/pandas/tests/util/test_deprecate.py index 92f422b8269f5..bdbf2ca2d028d 100644 --- a/pandas/tests/util/test_deprecate.py +++ b/pandas/tests/util/test_deprecate.py @@ -37,7 +37,9 @@ def new_func_with_deprecation(): def test_deprecate_ok(): - depr_func = deprecate("depr_func", new_func, "1.0", msg="Use new_func instead.") + depr_func = deprecate( + "depr_func", new_func, "1.0", msg="Use new_func instead.", klass=FutureWarning + ) with tm.assert_produces_warning(FutureWarning): result = depr_func() @@ -48,7 +50,11 @@ def test_deprecate_ok(): def test_deprecate_no_docstring(): depr_func = deprecate( - "depr_func", new_func_no_docstring, "1.0", msg="Use new_func instead." + "depr_func", + new_func_no_docstring, + "1.0", + msg="Use new_func instead.", + klass=FutureWarning, ) with tm.assert_produces_warning(FutureWarning): result = depr_func() diff --git a/pandas/tests/util/test_deprecate_kwarg.py b/pandas/tests/util/test_deprecate_kwarg.py index b165e9fba0e4f..30923687a17e2 100644 --- a/pandas/tests/util/test_deprecate_kwarg.py +++ b/pandas/tests/util/test_deprecate_kwarg.py @@ -5,7 +5,7 @@ import pandas._testing as tm -@deprecate_kwarg("old", "new") +@deprecate_kwarg("old", "new", klass=FutureWarning) def _f1(new=False): return new @@ -13,7 +13,7 @@ def _f1(new=False): _f2_mappings = {"yes": True, "no": False} -@deprecate_kwarg("old", "new", _f2_mappings) +@deprecate_kwarg("old", "new", _f2_mappings, klass=FutureWarning) def _f2(new=False): return new @@ -22,7 +22,7 @@ def _f3_mapping(x): return x + 1 -@deprecate_kwarg("old", "new", _f3_mapping) +@deprecate_kwarg("old", "new", _f3_mapping, klass=FutureWarning) def _f3(new=0): return new @@ -70,7 +70,7 @@ def f4(new=None): return new -@deprecate_kwarg("old", None) +@deprecate_kwarg("old", None, klass=FutureWarning) def _f4(old=True, unchanged=True): return old, unchanged diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index e74ff89b11581..887f9ff1f2adb 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -10,7 +10,7 @@ @deprecate_nonkeyword_arguments( - version="1.1", allowed_args=["a", "b"], name="f_add_inputs" + version="1.1", allowed_args=["a", "b"], name="f_add_inputs", klass=FutureWarning ) def f(a, b=0, c=0, d=0): return a + b + c + d @@ -59,7 +59,7 @@ def test_three_arguments_with_name_in_warning(): assert f(6, 3, 3) == 12 -@deprecate_nonkeyword_arguments(version="1.1") +@deprecate_nonkeyword_arguments(version="1.1", klass=FutureWarning) def g(a, b=0, c=0, d=0): with tm.assert_produces_warning(None): return a + b + c + d @@ -88,7 +88,7 @@ def test_three_positional_argument_with_warning_message_analysis(): assert g(6, 3, 3) == 12 -@deprecate_nonkeyword_arguments(version="1.1") +@deprecate_nonkeyword_arguments(version="1.1", klass=FutureWarning) def h(a=0, b=0, c=0, d=0): return a + b + c + d @@ -113,7 +113,7 @@ def test_one_positional_argument_with_warning_message_analysis(): assert h(19) == 19 -@deprecate_nonkeyword_arguments(version="1.1") +@deprecate_nonkeyword_arguments(version="1.1", klass=FutureWarning) def i(a=0, /, b=0, *, c=0, d=0): return a + b + c + d @@ -123,7 +123,9 @@ def test_i_signature(): class Foo: - @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "bar"]) + @deprecate_nonkeyword_arguments( + version=None, allowed_args=["self", "bar"], klass=FutureWarning + ) def baz(self, bar=None, foobar=None): # pylint: disable=disallowed-name ... From 64d7591e4a13a048dee9905e91cf1d69c6716f20 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Date: Sat, 6 Apr 2024 03:37:16 +0300 Subject: [PATCH 06/17] Fix quantile tests --- pandas/core/window/expanding.py | 2 +- pandas/core/window/rolling.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/window/expanding.py b/pandas/core/window/expanding.py index abe853a8aa259..88e2a39520726 100644 --- a/pandas/core/window/expanding.py +++ b/pandas/core/window/expanding.py @@ -709,7 +709,7 @@ def kurt(self, numeric_only: bool = False): aggregation_description="quantile", agg_method="quantile", ) - @deprecate_kwarg(old_arg_name="quantile", new_arg_name="q") + @deprecate_kwarg(old_arg_name="quantile", new_arg_name="q", klass=FutureWarning) def quantile( self, q: float, diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 07998cdbd40b5..2dea1a8c7cea4 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -2556,7 +2556,7 @@ def kurt(self, numeric_only: bool = False): aggregation_description="quantile", agg_method="quantile", ) - @deprecate_kwarg(old_arg_name="quantile", new_arg_name="q") + @deprecate_kwarg(old_arg_name="quantile", new_arg_name="q", klass=FutureWarning) def quantile( self, q: float, From 213f79e6e55d8570040368eecbb7360ee669ecb6 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+DAzVise@users.noreply.github.com> Date: Tue, 16 Apr 2024 06:49:54 +0300 Subject: [PATCH 07/17] Write tests --- doc/source/whatsnew/v3.0.0.rst | 1 - .../test_deprecate_nonkeyword_arguments.py | 7 +++++- .../util/test_pandas_deprecation_warning.py | 25 +++++++++++++++++++ pandas/util/_decorators.py | 9 +++---- 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 pandas/tests/util/test_pandas_deprecation_warning.py diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index d597527066dc3..c06c44e755833 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -164,7 +164,6 @@ Other API changes Deprecations ~~~~~~~~~~~~ - Copy keyword ^^^^^^^^^^^^ diff --git a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py index 9f7a0d7bd92fe..ae2bd0b487019 100644 --- a/pandas/tests/util/test_deprecate_nonkeyword_arguments.py +++ b/pandas/tests/util/test_deprecate_nonkeyword_arguments.py @@ -113,7 +113,7 @@ def test_one_positional_argument_with_warning_message_analysis(): assert h(19) == 19 -@deprecate_nonkeyword_arguments(version="1.1", klass=FutureWarning) +@deprecate_nonkeyword_arguments(version="1.1", klass=UserWarning) def i(a=0, /, b=0, *, c=0, d=0): return a + b + c + d @@ -122,6 +122,11 @@ def test_i_signature(): assert str(inspect.signature(i)) == "(*, a=0, b=0, c=0, d=0)" +def test_i_warns_klass(): + with tm.assert_produces_warning(UserWarning): + assert i(1, 2) == 3 + + class Foo: @deprecate_nonkeyword_arguments( version=None, allowed_args=["self", "bar"], klass=FutureWarning diff --git a/pandas/tests/util/test_pandas_deprecation_warning.py b/pandas/tests/util/test_pandas_deprecation_warning.py new file mode 100644 index 0000000000000..1a813b6eb4afb --- /dev/null +++ b/pandas/tests/util/test_pandas_deprecation_warning.py @@ -0,0 +1,25 @@ +import warnings + +from pandas.util._decorators import deprecate_kwarg +from pandas.util._exceptions import Pandas40DeprecationWarning + +import pandas._testing as tm + + +def f1(): + warnings.warn("f1", Pandas40DeprecationWarning) + + +def test_function_warns_pandas_deprecation_warning(): + with tm.assert_produces_warning(DeprecationWarning): + f1() + + +@deprecate_kwarg("old", "new") +def f2(new=0): + return new + + +def test_decorator_warns_pandas_deprecation_warning(): + with tm.assert_produces_warning(DeprecationWarning): + f2(old=1) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 3d09cda63c546..d5ec738f1e195 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -54,8 +54,7 @@ def deprecate( alt_name : str, optional Name to use in preference of alternative.__name__. klass : Warning, optional - The warning class to use. Defaults to FutureWarning in the - last minor version before a major release, otherwise DeprecationWarning. + The warning class to use. stacklevel : int, default 2 msg : str The message to display in the warning. @@ -124,8 +123,7 @@ def deprecate_kwarg( new arguments. A callable must do its own value checking; values not found in a dict will be forwarded unchanged. klass : Warning, optional - The warning class to use. Defaults to FutureWarning in the - last minor version before a major release, otherwise DeprecationWarning. + The warning class to use. stacklevel : int, default 2 Examples @@ -300,8 +298,7 @@ def deprecate_nonkeyword_arguments( is used. klass : Warning, optional - The warning class to use. Defaults to FutureWarning in the - last minor version before a major release, otherwise DeprecationWarning. + The warning class to use. """ klass = klass or Pandas40DeprecationWarning From c96551cdb8d4cf18269bac5b8808d3e91e98ca21 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Tue, 21 May 2024 18:17:55 +0300 Subject: [PATCH 08/17] Use Pandas40DeprecationWarning for new deprecations --- pandas/core/generic.py | 5 +-- pandas/core/indexes/accessors.py | 9 ++-- pandas/core/window/expanding.py | 1 - pandas/core/window/rolling.py | 1 - pandas/tests/extension/test_arrow.py | 5 ++- .../tests/frame/methods/test_reindex_like.py | 6 ++- .../tests/io/json/test_json_table_schema.py | 6 ++- pandas/tests/io/json/test_pandas.py | 43 ++++++++++--------- pandas/tests/io/test_gcs.py | 4 +- pandas/tests/resample/test_datetime_index.py | 3 +- .../series/accessors/test_cat_accessor.py | 4 +- .../series/accessors/test_dt_accessor.py | 3 +- .../tests/series/methods/test_reindex_like.py | 10 +++-- 13 files changed, 58 insertions(+), 42 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f6874a3a3113c..32ca315876efe 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -101,7 +101,6 @@ Pandas40DeprecationWarning, find_stack_level, ) - from pandas.util._validators import ( check_dtype_backend, validate_ascending, @@ -2568,7 +2567,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.", - FutureWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) elif date_format == "epoch": @@ -2576,7 +2575,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.", - FutureWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 3cb51f7447677..0e6c85f56ff82 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -14,7 +14,10 @@ import numpy as np from pandas._libs import lib -from pandas.util._exceptions import find_stack_level +from pandas.util._exceptions import ( + Pandas40DeprecationWarning, + find_stack_level, +) from pandas.core.dtypes.common import ( is_integer_dtype, @@ -218,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", - FutureWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) return cast(ArrowExtensionArray, self._parent.array)._dt_to_pytimedelta() @@ -479,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", - FutureWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) return self._get_values().to_pytimedelta() diff --git a/pandas/core/window/expanding.py b/pandas/core/window/expanding.py index 15646b46f86aa..f14954cd9a4b0 100644 --- a/pandas/core/window/expanding.py +++ b/pandas/core/window/expanding.py @@ -706,7 +706,6 @@ def kurt(self, numeric_only: bool = False): aggregation_description="quantile", agg_method="quantile", ) - def quantile( self, q: float, diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 4a0a39aabd13f..2243d8dd1a613 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -2553,7 +2553,6 @@ def kurt(self, numeric_only: bool = False): aggregation_description="quantile", agg_method="quantile", ) - def quantile( self, q: float, diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 7d31fe6085c3a..d33ebf2574f9f 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -43,6 +43,7 @@ pa_version_under13p0, pa_version_under14p0, ) +from pandas.util._exceptions import Pandas40DeprecationWarning import pandas.util._test_decorators as td from pandas.core.dtypes.dtypes import ( @@ -2862,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 03968dcbb6314..3ab6752f8e6b5 100644 --- a/pandas/tests/frame/methods/test_reindex_like.py +++ b/pandas/tests/frame/methods/test_reindex_like.py @@ -1,6 +1,8 @@ import numpy as np import pytest +from pandas.util._exceptions import Pandas40DeprecationWarning + from pandas import DataFrame import pandas._testing as tm @@ -22,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(FutureWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = df.reindex_like(df, method=method, tolerance=0) tm.assert_frame_equal(df, result) - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0]) tm.assert_frame_equal(df, result) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index a0d5b3a741aaf..18c1d6bd395ce 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -7,6 +7,8 @@ import numpy as np import pytest +from pandas.util._exceptions import Pandas40DeprecationWarning + from pandas.core.dtypes.dtypes import ( CategoricalDtype, DatetimeTZDtype, @@ -460,7 +462,9 @@ def test_date_format_raises(self, df_table): "version, please use 'iso' date format instead." ) with pytest.raises(ValueError, match=error_msg): - with tm.assert_produces_warning(FutureWarning, match=warning_msg): + with tm.assert_produces_warning( + Pandas40DeprecationWarning, match=warning_msg + ): df_table.to_json(orient="table", date_format="epoch") # others work diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index c4065ea01988f..67f6738e81f4a 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -13,6 +13,7 @@ from pandas._config import using_pyarrow_string_dtype from pandas.compat import IS64 +from pandas.util._exceptions import Pandas40DeprecationWarning import pandas.util._test_decorators as td import pandas as pd @@ -142,7 +143,7 @@ def test_frame_non_unique_columns(self, orient, data): "in a future version, please use 'iso' date format instead." ) if df.iloc[:, 0].dtype == "datetime64[ns]": - expected_warning = FutureWarning + expected_warning = Pandas40DeprecationWarning with tm.assert_produces_warning(expected_warning, match=msg): result = read_json( @@ -774,7 +775,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): data = StringIO(s.to_json()) result = read_json(data, typ="series", dtype=dtype) tm.assert_series_equal(result, expected) @@ -825,13 +826,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): json = StringIO(df.to_json(date_unit="ns")) result = read_json(json, convert_dates=False) @@ -842,7 +843,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): json = StringIO(ts.to_json()) result = read_json(json, typ="series") tm.assert_series_equal(result, ts) @@ -860,7 +861,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 = FutureWarning + expected_warning = Pandas40DeprecationWarning else: expected = ( '{"2020-01-01T00:00:00.000":"2020-01-01T00:00:00.000","null":null}' @@ -973,7 +974,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): json = df.to_json(date_format="epoch", date_unit=unit) # force date unit @@ -993,13 +994,13 @@ def test_date_unit(self, unit, datetime_frame): DataFrame( {"A": ["a", "b", "c"], "B": pd.to_timedelta(np.arange(3), unit="D")} ), - FutureWarning, + Pandas40DeprecationWarning, ), ( DataFrame( {"A": pd.to_datetime(["2020-01-01", "2020-02-01", "2020-03-01"])} ), - FutureWarning, + Pandas40DeprecationWarning, ), ], ) @@ -1085,7 +1086,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): json = StringIO(dfj2.to_json()) result = read_json(json, dtype={"ints": np.int64, "bools": np.bool_}) tm.assert_frame_equal(result, result) @@ -1127,20 +1128,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): json = frame.to_json() tm.assert_frame_equal(frame, read_json(StringIO(json)).apply(converter)) @@ -1156,7 +1157,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): data = StringIO(frame.to_json(date_unit="ns")) result = read_json(data) result["a"] = pd.to_timedelta(result.a, unit="ns") @@ -1191,7 +1192,7 @@ def test_timedelta_to_json(self, as_object, date_format, timedelta_typ): '{"P1DT0H0M0S":"P1DT0H0M0S","P2DT0H0M0S":"P2DT0H0M0S","null":null}' ) else: - expected_warning = FutureWarning + expected_warning = Pandas40DeprecationWarning expected = '{"86400000":86400000,"172800000":172800000,"null":null}' if as_object: @@ -1210,7 +1211,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 = FutureWarning + warn = Pandas40DeprecationWarning if as_object: ser = ser.astype(object) warn = None @@ -1306,13 +1307,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): assert stz.to_json() == s_naive.to_json() def test_sparse(self): @@ -1582,7 +1583,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): dfjson = expected.to_json(orient=orient) result = read_json( @@ -1776,7 +1777,7 @@ def test_timedelta_as_label(self, date_format, key): expected_warning = None if date_format == "epoch": - expected_warning = FutureWarning + expected_warning = Pandas40DeprecationWarning msg = ( "'epoch' date format is deprecated and will be removed in a future " @@ -2021,7 +2022,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 = FutureWarning + expected_warning = Pandas40DeprecationWarning 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 4b2be41d0c9f9..85212348bc4df 100644 --- a/pandas/tests/io/test_gcs.py +++ b/pandas/tests/io/test_gcs.py @@ -7,6 +7,8 @@ import numpy as np import pytest +from pandas.util._exceptions import Pandas40DeprecationWarning + from pandas import ( DataFrame, Index, @@ -82,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 c38d223c9d6a0..387830bc6bb2e 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -8,6 +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 import pandas.util._test_decorators as td import pandas as pd @@ -1300,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(FutureWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): 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/series/accessors/test_cat_accessor.py b/pandas/tests/series/accessors/test_cat_accessor.py index ce8ea27ea1fa2..4c9034d645844 100644 --- a/pandas/tests/series/accessors/test_cat_accessor.py +++ b/pandas/tests/series/accessors/test_cat_accessor.py @@ -1,6 +1,8 @@ import numpy as np import pytest +from pandas.util._exceptions import Pandas40DeprecationWarning + from pandas import ( Categorical, DataFrame, @@ -202,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(FutureWarning) + warn_cls.append(Pandas40DeprecationWarning) 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 8c60f7beb317d..074b23e1d5597 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -12,6 +12,7 @@ import pytz from pandas._libs.tslibs.timezones import maybe_get_tz +from pandas.util._exceptions import Pandas40DeprecationWarning from pandas.core.dtypes.common import ( is_integer_dtype, @@ -193,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(FutureWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 10b8ac5817636..81311fbe14f18 100644 --- a/pandas/tests/series/methods/test_reindex_like.py +++ b/pandas/tests/series/methods/test_reindex_like.py @@ -2,6 +2,8 @@ import numpy as np +from pandas.util._exceptions import Pandas40DeprecationWarning + from pandas import Series import pandas._testing as tm @@ -20,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(FutureWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = series1.reindex_like(series2, method="pad") expected = Series([5, np.nan], index=[day1, day3]) tm.assert_series_equal(result, expected) @@ -33,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(FutureWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = ser.reindex_like(other, method="nearest") tm.assert_series_equal(expected, result) - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = ser.reindex_like(other, method="nearest", tolerance=1) tm.assert_series_equal(expected, result) - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = ser.reindex_like(other, method="nearest", tolerance=[1, 2, 3, 4]) tm.assert_series_equal(expected, result) From 9f2d5694b0ede5cb16f2a71cb37e9064f88bb03f Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Thu, 6 Jun 2024 07:26:06 +0300 Subject: [PATCH 09/17] Update groupby corrwith's warning --- pandas/core/groupby/generic.py | 7 +++++-- 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 | 5 +++-- pandas/tests/groupby/test_numeric_only.py | 5 +++-- pandas/tests/groupby/transform/test_transform.py | 5 +++-- pandas/tests/io/json/test_pandas.py | 1 - 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 945b9f9c14c0b..0752b3c58495a 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -33,7 +33,10 @@ Substitution, doc, ) -from pandas.util._exceptions import find_stack_level +from pandas.util._exceptions import ( + Pandas40DeprecationWarning, + find_stack_level, +) from pandas.core.dtypes.common import ( ensure_int64, @@ -2791,7 +2794,7 @@ def corrwith( """ warnings.warn( "DataFrameGroupBy.corrwith is deprecated", - FutureWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) result = self._op_via_apply( diff --git a/pandas/tests/groupby/test_all_methods.py b/pandas/tests/groupby/test_all_methods.py index 945c3e421a132..43689c76fd85a 100644 --- a/pandas/tests/groupby/test_all_methods.py +++ b/pandas/tests/groupby/test_all_methods.py @@ -13,6 +13,8 @@ import pytest +from pandas.util._exceptions import Pandas40DeprecationWarning + import pandas as pd from pandas import DataFrame import pandas._testing as tm @@ -26,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 = FutureWarning + warn = Pandas40DeprecationWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -72,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 = FutureWarning + warn = Pandas40DeprecationWarning 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 75801b9e039f6..a96463788ccda 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -6,6 +6,8 @@ import numpy as np import pytest +from pandas.util._exceptions import Pandas40DeprecationWarning + import pandas as pd from pandas import ( DataFrame, @@ -1198,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 = FutureWarning + warn = Pandas40DeprecationWarning 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 010bd9ee52555..57776b8a78c67 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -3,6 +3,8 @@ import numpy as np import pytest +from pandas.util._exceptions import Pandas40DeprecationWarning + import pandas as pd from pandas import ( Categorical, @@ -1474,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 = FutureWarning + warn = Pandas40DeprecationWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -1520,7 +1522,7 @@ def test_dataframe_groupby_on_2_categoricals_when_observed_is_false( return if reduction_func == "corrwith": - warn = FutureWarning + warn = Pandas40DeprecationWarning warn_msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -1919,7 +1921,7 @@ def test_category_order_reducer( getattr(gb, reduction_func)(*args) return if reduction_func == "corrwith": - warn = FutureWarning + warn = Pandas40DeprecationWarning 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 4749e845a0e59..f73440acedabc 100644 --- a/pandas/tests/groupby/test_groupby_dropna.py +++ b/pandas/tests/groupby/test_groupby_dropna.py @@ -2,6 +2,7 @@ import pytest from pandas.compat.pyarrow import pa_version_under10p1 +from pandas.util._exceptions import Pandas40DeprecationWarning from pandas.core.dtypes.missing import na_value_for_dtype @@ -544,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 = FutureWarning + warn = Pandas40DeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -575,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 = FutureWarning + warn = Pandas40DeprecationWarning 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 afbc64429e93c..f3e193be23a74 100644 --- a/pandas/tests/groupby/test_numeric_only.py +++ b/pandas/tests/groupby/test_numeric_only.py @@ -3,6 +3,7 @@ import pytest from pandas._libs import lib +from pandas.util._exceptions import Pandas40DeprecationWarning import pandas as pd from pandas import ( @@ -257,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 = FutureWarning + warn = Pandas40DeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -304,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 = FutureWarning + warn = Pandas40DeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index 726c57081373c..45471fcc5bc8b 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -4,6 +4,7 @@ import pytest from pandas._libs import lib +from pandas.util._exceptions import Pandas40DeprecationWarning from pandas.core.dtypes.common import ensure_platform_int @@ -1105,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 = FutureWarning + warn = Pandas40DeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None @@ -1476,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 = FutureWarning + warn = Pandas40DeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 90e2304db60d8..2839097294523 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -151,7 +151,6 @@ def test_frame_non_unique_columns(self, orient, data, request): if df.iloc[:, 0].dtype == "datetime64[s]": expected_warning = Pandas40DeprecationWarning - with tm.assert_produces_warning(expected_warning, match=msg): result = read_json( StringIO(df.to_json(orient=orient)), orient=orient, convert_dates=["x"] From d5dbc268d7d8e77a0a5e315b09ce9a30a557392e Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Thu, 6 Jun 2024 07:29:52 +0300 Subject: [PATCH 10/17] Update make_block's warning --- pandas/core/internals/api.py | 3 ++- pandas/io/feather_format.py | 3 ++- pandas/io/parquet.py | 5 +++-- pandas/io/parsers/arrow_parser_wrapper.py | 7 +++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pandas/core/internals/api.py b/pandas/core/internals/api.py index 04944db2ebd9c..4b73645139d47 100644 --- a/pandas/core/internals/api.py +++ b/pandas/core/internals/api.py @@ -15,6 +15,7 @@ import numpy as np from pandas._libs.internals import BlockPlacement +from pandas.util._exceptions import Pandas40DeprecationWarning from pandas.core.dtypes.common import pandas_dtype from pandas.core.dtypes.dtypes import ( @@ -93,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.", - DeprecationWarning, + Pandas40DeprecationWarning, stacklevel=2, ) diff --git a/pandas/io/feather_format.py b/pandas/io/feather_format.py index 16d4e1f9ea25d..788d74928d7a4 100644 --- a/pandas/io/feather_format.py +++ b/pandas/io/feather_format.py @@ -13,6 +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._validators import check_dtype_backend import pandas as pd @@ -136,7 +137,7 @@ def read_feather( warnings.filterwarnings( "ignore", "make_block is deprecated", - DeprecationWarning, + Pandas40DeprecationWarning, ) return feather.read_feather( diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index 306b144811898..31f80b5108fda 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -21,6 +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._validators import check_dtype_backend import pandas as pd @@ -278,7 +279,7 @@ def read( filterwarnings( "ignore", "make_block is deprecated", - DeprecationWarning, + Pandas40DeprecationWarning, ) result = pa_table.to_pandas(**to_pandas_kwargs) @@ -397,7 +398,7 @@ def read( filterwarnings( "ignore", "make_block is deprecated", - DeprecationWarning, + Pandas40DeprecationWarning, ) 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 cffdb28e2c9e4..c5b4adfd4b527 100644 --- a/pandas/io/parsers/arrow_parser_wrapper.py +++ b/pandas/io/parsers/arrow_parser_wrapper.py @@ -11,7 +11,10 @@ ParserError, ParserWarning, ) -from pandas.util._exceptions import find_stack_level +from pandas.util._exceptions import ( + Pandas40DeprecationWarning, + find_stack_level, +) from pandas.core.dtypes.common import pandas_dtype from pandas.core.dtypes.inference import is_integer @@ -291,7 +294,7 @@ def read(self) -> DataFrame: warnings.filterwarnings( "ignore", "make_block is deprecated", - DeprecationWarning, + Pandas40DeprecationWarning, ) if dtype_backend == "pyarrow": frame = table.to_pandas(types_mapper=pd.ArrowDtype) From 02ec7b224f7c2d671bd04d964dd6eb93e30190e1 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Thu, 6 Jun 2024 07:31:54 +0300 Subject: [PATCH 11/17] Add Pandas50DeprecationWarning for deprecations planned for 5.0 --- pandas/util/_exceptions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/util/_exceptions.py b/pandas/util/_exceptions.py index 89361e63cb2eb..6f3cda76f7fd2 100644 --- a/pandas/util/_exceptions.py +++ b/pandas/util/_exceptions.py @@ -12,6 +12,7 @@ from types import FrameType Pandas40DeprecationWarning = DeprecationWarning +Pandas50DeprecationWarning = DeprecationWarning @contextlib.contextmanager From 2570d57817a45e8d699f744c1b7f98bbc8862343 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Thu, 6 Jun 2024 18:18:49 +0300 Subject: [PATCH 12/17] Fix test failures --- pandas/tests/groupby/test_raises.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_raises.py b/pandas/tests/groupby/test_raises.py index 5a8192a9ffe02..97ab494c58599 100644 --- a/pandas/tests/groupby/test_raises.py +++ b/pandas/tests/groupby/test_raises.py @@ -8,6 +8,8 @@ import numpy as np import pytest +from pandas.util._exceptions import Pandas40DeprecationWarning + from pandas import ( Categorical, DataFrame, @@ -85,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 FutureWarning + warn_klass = None if warn_msg == "" else Pandas40DeprecationWarning with tm.assert_produces_warning(warn_klass, match=warn_msg, check_stacklevel=False): if klass is None: if how == "method": 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 13/17] 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 From 740a8c2d3c66e8c93d906ac0d96a39957e3c46d9 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Fri, 7 Jun 2024 13:48:16 +0300 Subject: [PATCH 14/17] Revert "Add CurrentPandasWarning" This reverts commit f4e0d00866fc56613a269b637723d4eb30f3655a. --- 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, 115 insertions(+), 116 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 7d021705d18e5..337e50233a045 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 ( - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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.", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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.", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) return cls.fromtimestamp(ts, tz="UTC") diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3050214fdcbaa..d2841c8010629 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -98,7 +98,7 @@ doc, ) from pandas.util._exceptions import ( - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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.", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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.", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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.", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 0ba5b95c70e72..0752b3c58495a 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -34,7 +34,7 @@ doc, ) from pandas.util._exceptions import ( - CurrentDeprecationWarning, + Pandas40DeprecationWarning, find_stack_level, ) @@ -2794,7 +2794,7 @@ def corrwith( """ warnings.warn( "DataFrameGroupBy.corrwith is deprecated", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) result = self._op_via_apply( diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index ecb26e765cd4c..0e6c85f56ff82 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 ( - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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 4457ffdc98187..4b73645139d47 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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.", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, stacklevel=2, ) diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 6b6aec8e3782e..616b870f957b1 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 ( - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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.", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/io/feather_format.py b/pandas/io/feather_format.py index fdb9c78151f88..788d74928d7a4 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, ) return feather.read_feather( diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index 5670040b52f12..31f80b5108fda 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning from pandas.util._validators import check_dtype_backend import pandas as pd @@ -279,7 +279,7 @@ def read( filterwarnings( "ignore", "make_block is deprecated", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, ) result = pa_table.to_pandas(**to_pandas_kwargs) @@ -398,7 +398,7 @@ def read( filterwarnings( "ignore", "make_block is deprecated", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, ) 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 cec681ba40389..c5b4adfd4b527 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 ( - CurrentDeprecationWarning, + Pandas40DeprecationWarning, find_stack_level, ) @@ -294,7 +294,7 @@ def read(self) -> DataFrame: warnings.filterwarnings( "ignore", "make_block is deprecated", - CurrentDeprecationWarning, + Pandas40DeprecationWarning, ) 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 f5e1427172bba..ec0e1d902c392 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match="copy"): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match="copy"): getattr(df, meth)(copy=False, **kwargs) if meth != "transpose": - with tm.assert_produces_warning(CurrentDeprecationWarning, match="copy"): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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( - CurrentDeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): df.reindex_like(df, copy=False) with tm.assert_produces_warning( - CurrentDeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): df.a.reindex_like(df.a, copy=False) with tm.assert_produces_warning( - CurrentDeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): df.align(df, copy=False) with tm.assert_produces_warning( - CurrentDeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, 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( - CurrentDeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): df.merge(df, copy=False) with tm.assert_produces_warning( - CurrentDeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, match="copy", check_stacklevel=False ): merge(df, df, copy=False) with tm.assert_produces_warning( - CurrentDeprecationWarning, match="copy", check_stacklevel=False + Pandas40DeprecationWarning, 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 a58285d5ca2d1..8096975f8dc90 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 0b12d82e457d2..3ab6752f8e6b5 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = df.reindex_like(df, method=method, tolerance=0) tm.assert_frame_equal(df, result) - with tm.assert_produces_warning(CurrentDeprecationWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): 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 199ce97e25650..43689c76fd85a 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 3cc7833b8d919..a96463788ccda 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 3f177f34e7cf7..57776b8a78c67 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 71c706aba9f88..f73440acedabc 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 fe9d863408a3c..f3e193be23a74 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 a1d3e05981e7c..97ab494c58599 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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 CurrentDeprecationWarning + warn_klass = None if warn_msg == "" else Pandas40DeprecationWarning 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 608cf6b8028a9..45471fcc5bc8b 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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 57018bb7229b0..96661d7948ba0 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 9d2ad482b50bb..d59355fa8a364 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 d45b71cded33e..18c1d6bd395ce 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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( - CurrentDeprecationWarning, match=warning_msg + Pandas40DeprecationWarning, 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 356d739805772..2839097294523 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + expected_warning = Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 = CurrentDeprecationWarning + expected_warning = Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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")} ), - CurrentDeprecationWarning, + Pandas40DeprecationWarning, ), ( DataFrame( {"A": pd.to_datetime(["2020-01-01", "2020-02-01", "2020-03-01"])} ), - CurrentDeprecationWarning, + Pandas40DeprecationWarning, ), ], ) @@ -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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 = CurrentDeprecationWarning + expected_warning = Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + warn = Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 = CurrentDeprecationWarning + expected_warning = Pandas40DeprecationWarning 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 = CurrentDeprecationWarning + expected_warning = Pandas40DeprecationWarning 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 3a4199fdaef14..e4de725ead5c6 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 8d520ed2132ed..387830bc6bb2e 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): 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 eee292790fec9..33779bb4c0740 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, match=msg): Timestamp.utcnow() def test_utcfromtimestamp_deprecated(self): # GH#56680 msg = "Timestamp.utcfromtimestamp is deprecated" - with tm.assert_produces_warning(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 80925aa9f4289..ba21f7eb6dd69 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 c60bb51cf0234..4c9034d645844 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning) + warn_cls.append(Pandas40DeprecationWarning) 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 4e60e9e96930e..2dc27e726a6c4 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning, match=msg): + with tm.assert_produces_warning(Pandas40DeprecationWarning, 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 4e462cdf5c1be..81311fbe14f18 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning 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(CurrentDeprecationWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): 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(CurrentDeprecationWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = ser.reindex_like(other, method="nearest") tm.assert_series_equal(expected, result) - with tm.assert_produces_warning(CurrentDeprecationWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): result = ser.reindex_like(other, method="nearest", tolerance=1) tm.assert_series_equal(expected, result) - with tm.assert_produces_warning(CurrentDeprecationWarning): + with tm.assert_produces_warning(Pandas40DeprecationWarning): 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 f8a16e6ed8961..1a813b6eb4afb 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 CurrentDeprecationWarning +from pandas.util._exceptions import Pandas40DeprecationWarning import pandas._testing as tm def f1(): - warnings.warn("f1", CurrentDeprecationWarning) + warnings.warn("f1", Pandas40DeprecationWarning) def test_function_warns_pandas_deprecation_warning(): diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 33ab5b22557fc..faaaf10d160ac 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -17,7 +17,7 @@ T, ) from pandas.util._exceptions import ( - CurrentDeprecationWarning, + Pandas40DeprecationWarning, 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 CurrentDeprecationWarning + klass = klass or Pandas40DeprecationWarning 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 CurrentDeprecationWarning + klass = klass or Pandas40DeprecationWarning 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 CurrentDeprecationWarning + klass = klass or Pandas40DeprecationWarning def decorate(func): old_sig = inspect.signature(func) diff --git a/pandas/util/_exceptions.py b/pandas/util/_exceptions.py index 4f3ec22d89fe1..6f3cda76f7fd2 100644 --- a/pandas/util/_exceptions.py +++ b/pandas/util/_exceptions.py @@ -11,9 +11,8 @@ from collections.abc import Generator from types import FrameType -Pandas4DeprecationWarning = DeprecationWarning -Pandas5DeprecationWarning = DeprecationWarning -CurrentDeprecationWarning = Pandas4DeprecationWarning +Pandas40DeprecationWarning = DeprecationWarning +Pandas50DeprecationWarning = DeprecationWarning @contextlib.contextmanager From 23bbfb8412781ca06042af38ab72e95de7bf3106 Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Fri, 7 Jun 2024 13:56:49 +0300 Subject: [PATCH 15/17] Add CurrentDeprecationWarning --- pandas/tests/groupby/test_raises.py | 4 ++-- pandas/tests/util/test_pandas_deprecation_warning.py | 4 ++-- pandas/util/_decorators.py | 8 ++++---- pandas/util/_exceptions.py | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) 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/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..6bbf861ca8cff 100644 --- a/pandas/util/_exceptions.py +++ b/pandas/util/_exceptions.py @@ -13,6 +13,7 @@ Pandas40DeprecationWarning = DeprecationWarning Pandas50DeprecationWarning = DeprecationWarning +CurrentDeprecationWarning = Pandas40DeprecationWarning @contextlib.contextmanager From bc60ecb06ce164bd21364ec36d7d7f51e9fd5f9c Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:05:32 +0300 Subject: [PATCH 16/17] Rename variable --- 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 +-- .../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 ++--- pandas/util/_exceptions.py | 6 +-- 30 files changed, 108 insertions(+), 108 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 337e50233a045..e75a73f5c0ab6 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, + Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, stacklevel=find_stack_level(), ) return cls.fromtimestamp(ts, tz="UTC") diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d2841c8010629..8f641b4a6c226 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -98,7 +98,7 @@ doc, ) from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 0752b3c58495a..40a51d1c80c1f 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -34,7 +34,7 @@ doc, ) from pandas.util._exceptions import ( - Pandas40DeprecationWarning, + Pandas4DeprecationWarning, find_stack_level, ) @@ -2794,7 +2794,7 @@ def corrwith( """ warnings.warn( "DataFrameGroupBy.corrwith is deprecated", - Pandas40DeprecationWarning, + Pandas4DeprecationWarning, 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..62e8c49292499 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, + Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, 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..1681eff7675e7 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 Pandas4DeprecationWarning 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, + Pandas4DeprecationWarning, stacklevel=2, ) diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 616b870f957b1..41c0cb6ec9182 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, + Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/io/feather_format.py b/pandas/io/feather_format.py index 788d74928d7a4..0d2bf449d2172 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 Pandas4DeprecationWarning 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, + Pandas4DeprecationWarning, ) return feather.read_feather( diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index 31f80b5108fda..e6e2f963db407 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 Pandas4DeprecationWarning 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, + Pandas4DeprecationWarning, ) result = pa_table.to_pandas(**to_pandas_kwargs) @@ -398,7 +398,7 @@ def read( filterwarnings( "ignore", "make_block is deprecated", - Pandas40DeprecationWarning, + Pandas4DeprecationWarning, ) 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..ea26f620a924e 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, + Pandas4DeprecationWarning, find_stack_level, ) @@ -294,7 +294,7 @@ def read(self) -> DataFrame: warnings.filterwarnings( "ignore", "make_block is deprecated", - Pandas40DeprecationWarning, + Pandas4DeprecationWarning, ) 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..57bb10b8be12a 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, match="copy"): getattr(df, meth)(copy=False, **kwargs) if meth != "transpose": - with tm.assert_produces_warning(Pandas40DeprecationWarning, match="copy"): + with tm.assert_produces_warning(Pandas4DeprecationWarning, 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 + Pandas4DeprecationWarning, match="copy", check_stacklevel=False ): df.reindex_like(df, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + Pandas4DeprecationWarning, match="copy", check_stacklevel=False ): df.a.reindex_like(df.a, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + Pandas4DeprecationWarning, match="copy", check_stacklevel=False ): df.align(df, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + Pandas4DeprecationWarning, 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 + Pandas4DeprecationWarning, match="copy", check_stacklevel=False ): df.merge(df, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + Pandas4DeprecationWarning, match="copy", check_stacklevel=False ): merge(df, df, copy=False) with tm.assert_produces_warning( - Pandas40DeprecationWarning, match="copy", check_stacklevel=False + Pandas4DeprecationWarning, 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..619f846badfe2 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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..7c6822a166852 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning): 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(Pandas4DeprecationWarning): 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..87b8155cf0ffc 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 Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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..020e156c83554 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 Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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..a7a7eeae39085 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 Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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..631c75bfb40b8 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 Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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..3d9574b978815 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 Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning msg = "DataFrameGroupBy.corrwith is deprecated" else: warn = None diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index 45471fcc5bc8b..2e35ae8d491c0 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 Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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..cf3acbd87f1bb 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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..5fd21806f724f 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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..a6a11a4ff7022 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 Pandas4DeprecationWarning 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 + Pandas4DeprecationWarning, 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..43edcd529f8be 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 Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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 = Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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, + Pandas4DeprecationWarning, ), ( DataFrame( {"A": pd.to_datetime(["2020-01-01", "2020-02-01", "2020-03-01"])} ), - Pandas40DeprecationWarning, + Pandas4DeprecationWarning, ), ], ) @@ -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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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 = Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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 = Pandas4DeprecationWarning 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 = Pandas4DeprecationWarning 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..b416c9bccd9fe 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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..0b7d1a5382578 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning): 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..5dce9c3660c28 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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..aa4234db92afd 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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(Pandas4DeprecationWarning, 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..0df0e301a310f 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning) 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..19bba4dd17f86 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning, 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..01f5ed308eeb7 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 Pandas4DeprecationWarning 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(Pandas4DeprecationWarning): 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(Pandas4DeprecationWarning): result = ser.reindex_like(other, method="nearest") tm.assert_series_equal(expected, result) - with tm.assert_produces_warning(Pandas40DeprecationWarning): + with tm.assert_produces_warning(Pandas4DeprecationWarning): 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(Pandas4DeprecationWarning): result = ser.reindex_like(other, method="nearest", tolerance=[1, 2, 3, 4]) tm.assert_series_equal(expected, result) diff --git a/pandas/util/_exceptions.py b/pandas/util/_exceptions.py index 6bbf861ca8cff..4f3ec22d89fe1 100644 --- a/pandas/util/_exceptions.py +++ b/pandas/util/_exceptions.py @@ -11,9 +11,9 @@ from collections.abc import Generator from types import FrameType -Pandas40DeprecationWarning = DeprecationWarning -Pandas50DeprecationWarning = DeprecationWarning -CurrentDeprecationWarning = Pandas40DeprecationWarning +Pandas4DeprecationWarning = DeprecationWarning +Pandas5DeprecationWarning = DeprecationWarning +CurrentDeprecationWarning = Pandas4DeprecationWarning @contextlib.contextmanager From aacfbc1001a2a3cba5f8cbd12921965bd478336e Mon Sep 17 00:00:00 2001 From: Abdulaziz Aloqeely <52792999+Aloqeely@users.noreply.github.com> Date: Sun, 9 Jun 2024 18:31:30 +0300 Subject: [PATCH 17/17] Add reasoning in whatsnew --- doc/source/whatsnew/v3.0.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index c68df4c853302..6dfce8bd086f5 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -28,6 +28,8 @@ New Deprecation Policy ^^^^^^^^^^^^^^^^^^^^^^ pandas 3.0.0 introduces a new 3-stage deprecation policy: using ``DeprecationWarning`` initially, then switching to ``FutureWarning`` for broader visibility in the last minor version before the next major release, and then removal of the deprecated functionality in the major release. +This was done to give downstream packages more time to adjust to pandas deprecations, which should reduce the amount of warnings that a user gets from code that isn't theirs. + .. _whatsnew_300.enhancements.other: Other enhancements