Skip to content

DEPR: non-keyword arguments in any #44896

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

Merged
merged 42 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
59bd617
tighten return type in any
yadav-sachin Dec 15, 2021
389cb03
correct overload definitions
yadav-sachin Dec 15, 2021
076efc0
add overload def for NDFrame input
yadav-sachin Dec 15, 2021
7f643d6
remove overload defs and define function any in sub-classes
yadav-sachin Dec 16, 2021
d6df993
Merge branch 'master' of github.com:pandas-dev/pandas into any_return…
yadav-sachin Dec 16, 2021
d2653da
add overload defs for level
yadav-sachin Dec 17, 2021
0f15b62
correct default val in overload defs
yadav-sachin Dec 17, 2021
831481c
deprecate non-keyword args
yadav-sachin Dec 18, 2021
284efd3
add whatsnew note
yadav-sachin Dec 21, 2021
e002897
modify return types and add tests
yadav-sachin Dec 21, 2021
912b040
Merge branch 'master' of github.com:pandas-dev/pandas into any_return…
yadav-sachin Dec 21, 2021
b229a3b
move non-keyword deprecation to generic
yadav-sachin Dec 24, 2021
0c3ebd7
correct deprecation decorators
yadav-sachin Dec 24, 2021
799e12b
Merge remote branch 'main' into any_return_type
yadav-sachin Feb 28, 2022
3441523
Merge remote-tracking branch 'upstream/main' into any_return_type
yadav-sachin Mar 3, 2022
cdb96f7
remove imports in test assertions
yadav-sachin Apr 1, 2022
49a1b0b
Merge remote-tracking branch 'upstream/main' into any_return_type
yadav-sachin Apr 1, 2022
76003ed
place deprecate_nonkeyword at correct place
yadav-sachin Apr 4, 2022
787616d
remove changes from frame.py, series.py
yadav-sachin Apr 4, 2022
0375347
readd changes in frame, series without actual implementations
yadav-sachin Apr 4, 2022
5573d34
Merge remote-tracking branch 'upstream/main' into any_return_type
yadav-sachin Apr 4, 2022
a13ee6f
place deprecate_nonkeyword at other place
yadav-sachin Apr 4, 2022
6e5b3ac
add name argument to deprecate_non_keyword_args decorator
yadav-sachin Apr 4, 2022
63ae9c1
add test for name in deprecate_nonkeyword_args
yadav-sachin Apr 4, 2022
1010e1e
remove changes from frame.py, series.py
yadav-sachin Apr 4, 2022
424b213
correct stacklevel in warning
yadav-sachin Apr 4, 2022
8007cf1
correct stacklevel
MarcoGorelli Apr 4, 2022
a361637
set stacklevel to default
yadav-sachin Apr 4, 2022
ea19d40
merge upstream/any_return_type into any_return_type
yadav-sachin Apr 5, 2022
2678298
move deprecation message to whatsnew v1.5.0.rst
yadav-sachin Apr 5, 2022
96de045
add name parameter in deprecate_non_keyword_args docstring
yadav-sachin Apr 5, 2022
86ad6ba
correct whitespace in deprecate_nonkeyword_args docstring
yadav-sachin Apr 5, 2022
7dec331
Merge remote-tracking branch 'upstream/main' into any_return_type
yadav-sachin Apr 5, 2022
b4b3a1f
update any non-keyword args in other tests
yadav-sachin Apr 7, 2022
11917aa
update any in doc
yadav-sachin Apr 7, 2022
35c71b6
update remaining any() calls in pandas/core
yadav-sachin Apr 7, 2022
0e6d5eb
correct docstring of isocalendar in pandas/core/indexes/accessors.py
yadav-sachin Apr 8, 2022
025c493
Merge remote-tracking branch 'upstream/main' into any_return_type
yadav-sachin Apr 8, 2022
59ac830
Merge branch 'main' into any_return_type
MarcoGorelli Apr 8, 2022
d9d14e9
Merge remote-tracking branch 'upstream/main' into any_return_type
yadav-sachin Apr 9, 2022
15bbc86
Merge branch 'any_return_type' of github.com:yadav-sachin/pandas into…
yadav-sachin Apr 9, 2022
a8dd741
Merge remote-tracking branch 'upstream/main' into any_return_type
yadav-sachin Apr 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8642,6 +8642,20 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs):

agg = aggregate

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
@doc(NDFrame.any, **_shared_doc_kwargs)
def any(
self: DataFrame,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on python/mypy#11759 (comment) it is possible to just have the type annotations without the actual implementation.

(Hope it doesn't break the doc generation.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, does this work (using ...)? I thought somethling like any : Callable[...] # or Probably a protocol but that will then not allow you to change the doc-string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure actually - @yadav-sachin shall we just remove any modifications to frame.py and series.py in this PR, to keep it focused (and to get it through)? Apologies for contradicting requests from my part

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, does this work (using ...)? I thought somethling like any : Callable[...] # or Probably a protocol but that will then not allow you to change the doc-string

When checking with mypy, I was not getting any errors with this method (using ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure actually - @yadav-sachin shall we just remove any modifications to frame.py and series.py in this PR, to keep it focused (and to get it through)? Apologies for contradicting requests from my part

No problem, have removed the changes from the two mentioned files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When checking with mypy, I was not getting any errors with this method (using ...)

I meant more whether this works in practice. I would expect that any() wouldn't do anything when called on Series/DataFrame (unless ... magically delegates to NDFrame - would be cool if it does).

axis: Axis = 0,
bool_only: bool | None = None,
skipna: bool = True,
level: Level | None = None,
**kwargs,
) -> Series | DataFrame:
return super().any(
axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs
)

@doc(
_shared_docs["transform"],
klass=_shared_doc_kwargs["klass"],
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10365,7 +10365,7 @@ def any(
skipna: bool_t = True,
level: Level | None = None,
**kwargs,
) -> Series | bool_t:
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep the return type here? -> DataFrame | Series | bool_t?

Also, as this is only used internally, we can make its arguments keyword-only right away without warning

Copy link
Contributor Author

@yadav-sachin yadav-sachin Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By making arguments keyword-only, do you mean placing arguments after ,*,? (context: https://medium.com/analytics-vidhya/keyword-only-arguments-in-python-3c1c00051720)

return self._logical_func(
"any", nanops.nanany, axis, bool_only, skipna, level, **kwargs
)
Expand Down
15 changes: 15 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
DtypeObj,
FillnaOptions,
IndexKeyFunc,
Level,
SingleManager,
StorageOptions,
TimedeltaConvertibleTypes,
Expand Down Expand Up @@ -4257,6 +4258,20 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):

agg = aggregate

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
@doc(NDFrame.any, **_shared_doc_kwargs)
def any(
self: Series,
axis: Axis = 0,
bool_only: bool | None = None,
skipna: bool = True,
level: Level | None = None,
**kwargs,
) -> bool | Series:
return super().any(
axis=axis, bool_only=bool_only, skipna=skipna, level=level, **kwargs
)

@doc(
_shared_docs["transform"],
klass=_shared_doc_kwargs["klass"],
Expand Down