-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Allow deprecate_nonkeyword_arguments to not specify version, show class name #41524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,7 +211,7 @@ def wrapper(*args, **kwargs) -> Callable[..., Any]: | |
return _deprecate_kwarg | ||
|
||
|
||
def _format_argument_list(allow_args: list[str] | int): | ||
def _format_argument_list(allow_args: list[str]): | ||
""" | ||
Convert the allow_args argument (either string or integer) of | ||
`deprecate_nonkeyword_arguments` function to a string describing | ||
|
@@ -231,21 +231,16 @@ def _format_argument_list(allow_args: list[str] | int): | |
|
||
Examples | ||
-------- | ||
`format_argument_list(0)` -> '' | ||
`format_argument_list(1)` -> 'except for the first argument' | ||
`format_argument_list(2)` -> 'except for the first 2 arguments' | ||
`format_argument_list([])` -> '' | ||
`format_argument_list(['a'])` -> "except for the arguments 'a'" | ||
`format_argument_list(['a', 'b'])` -> "except for the arguments 'a' and 'b'" | ||
`format_argument_list(['a', 'b', 'c'])` -> | ||
"except for the arguments 'a', 'b' and 'c'" | ||
""" | ||
if "self" in allow_args: | ||
allow_args.remove("self") | ||
if not allow_args: | ||
return "" | ||
elif allow_args == 1: | ||
return " except for the first argument" | ||
elif isinstance(allow_args, int): | ||
return f" except for the first {allow_args} arguments" | ||
elif len(allow_args) == 1: | ||
return f" except for the argument '{allow_args[0]}'" | ||
else: | ||
|
@@ -254,9 +249,17 @@ def _format_argument_list(allow_args: list[str] | int): | |
return f" except for the arguments {args} and '{last}'" | ||
|
||
|
||
def future_version_msg(version: str | None) -> str: | ||
"""Specify which version of pandas the deprecation will take place in.""" | ||
if version is None: | ||
return "In a future version of pandas" | ||
else: | ||
return f"Starting with pandas version {version}" | ||
|
||
|
||
def deprecate_nonkeyword_arguments( | ||
version: str, | ||
allowed_args: list[str] | int | None = None, | ||
version: str | None, | ||
allowed_args: list[str] | None = None, | ||
stacklevel: int = 2, | ||
) -> Callable: | ||
""" | ||
|
@@ -266,14 +269,13 @@ def deprecate_nonkeyword_arguments( | |
---------- | ||
version : str | ||
The version in which positional arguments will become | ||
keyword-only. | ||
keyword-only. If None, then the warning message won't | ||
specify any particular version. | ||
|
||
allowed_args : list or int, optional | ||
allowed_args : list, optional | ||
In case of list, it must be the list of names of some | ||
first arguments of the decorated functions that are | ||
OK to be given as positional arguments. In case of an | ||
integer, this is the number of positional arguments | ||
that will stay positional. In case of None value, | ||
OK to be given as positional arguments. In case of None value, | ||
defaults to list of all arguments not having the | ||
default value. | ||
|
||
|
@@ -294,14 +296,11 @@ def decorate(func): | |
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
arguments = _format_argument_list(allow_args) | ||
if isinstance(allow_args, (list, tuple)): | ||
num_allow_args = len(allow_args) | ||
else: | ||
num_allow_args = allow_args | ||
num_allow_args = len(allow_args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nbd, but this and the line above could be moved to the outer scope. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed - have fixed, thanks! |
||
if len(args) > num_allow_args: | ||
msg = ( | ||
f"Starting with Pandas version {version} all arguments of " | ||
f"{func.__name__}{arguments} will be keyword-only" | ||
f"{future_version_msg(version)} all arguments of " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for the message creation |
||
f"{func.__qualname__}{arguments} will be keyword-only" | ||
) | ||
warnings.warn(msg, FutureWarning, stacklevel=stacklevel) | ||
return func(*args, **kwargs) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional