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