Skip to content

Commit

Permalink
Write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloqeely committed Apr 16, 2024
1 parent 7071870 commit 213f79e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
1 change: 0 additions & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ Other API changes
Deprecations
~~~~~~~~~~~~


Copy keyword
^^^^^^^^^^^^

Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/util/test_deprecate_nonkeyword_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pandas/tests/util/test_pandas_deprecation_warning.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 3 additions & 6 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 213f79e

Please sign in to comment.