Skip to content
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

DEPR: support axis=None in DataFrame reductions #52042

Merged
merged 22 commits into from
May 25, 2023

Conversation

jbrockmendel
Copy link
Member

Haven't yet added tests or docs, want to see if anyone cares about the warnings we get in the groupby tests when we do e.g. gb.apply(np.sum)

@mroeschke mroeschke added Deprecate Functionality to remove in pandas Reduction Operations sum, mean, min, max, etc. labels Mar 17, 2023
@rhshadrach
Copy link
Member

Will users also see this message when doing np.sum(df)? Might make sense say DataFrame.sum or numpy.sum. Then the error message would also make sense in the groupby apply case.

@jbrockmendel
Copy link
Member Author

Looks like this does produce the warning for np.sum(df), will update

@jbrockmendel
Copy link
Member Author

Hmm looks like the warning also shows up for the built-in sum, but not min (while applying np.min already operates over axis=None)

Copy link
Contributor

@topper-123 topper-123 left a comment

Choose a reason for hiding this comment

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

Generally LGTM. There are some tests failing, but I guess that's fixable

@mroeschke
Copy link
Member


pandas/core/series.py:6050: error: Argument 1 of "prod" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6050: note: This violates the Liskov substitution principle
pandas/core/series.py:6050: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/series.py:6081: error: Argument 1 of "sem" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6081: note: This violates the Liskov substitution principle
pandas/core/series.py:6081: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/series.py:6092: error: Argument 1 of "var" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6092: note: This violates the Liskov substitution principle
pandas/core/series.py:6092: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/series.py:6103: error: Argument 1 of "std" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6103: note: This violates the Liskov substitution principle
pandas/core/series.py:6103: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11001: error: Argument 1 of "sum" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11001: note: This violates the Liskov substitution principle
pandas/core/frame.py:11001: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11013: error: Argument 1 of "prod" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11013: note: This violates the Liskov substitution principle
pandas/core/frame.py:11013: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11044: error: Argument 1 of "sem" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11044: note: This violates the Liskov substitution principle
pandas/core/frame.py:11044: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11055: error: Argument 1 of "var" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11055: note: This violates the Liskov substitution principle
pandas/core/frame.py:11055: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11066: error: Argument 1 of "std" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11066: note: This violates the Liskov substitution principle
pandas/core/frame.py:11066: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11096: error: Incompatible types in assignment (expression has type "Callable[[Optional[Union[int, Literal['index', 'columns', 'rows']]], bool, bool, int, KwArg(Any)], Any]", base class "NDFrame" defined the type as "Callable[[Union[int, None, Literal['index', 'columns', 'rows', _NoDefault.no_default]], bool, bool, int, KwArg(Any)], Any]")  [assignment]
Found 11 errors in 2 files (checked 1418 source files)

mypy (stubtest)............................................................Failed
- hook id: stubtest
- duration: 117.05s
- exit code: 1

error: not checking stubs due to mypy build errors:
pandas/core/series.py:6039: error: Argument 1 of "sum" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6039: note: This violates the Liskov substitution principle
pandas/core/series.py:6039: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/series.py:6050: error: Argument 1 of "prod" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6050: note: This violates the Liskov substitution principle
pandas/core/series.py:6050: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/series.py:6081: error: Argument 1 of "sem" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6081: note: This violates the Liskov substitution principle
pandas/core/series.py:6081: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/series.py:6092: error: Argument 1 of "var" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6092: note: This violates the Liskov substitution principle
pandas/core/series.py:6092: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/series.py:6103: error: Argument 1 of "std" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/series.py:6103: note: This violates the Liskov substitution principle
pandas/core/series.py:6103: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11001: error: Argument 1 of "sum" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11001: note: This violates the Liskov substitution principle
pandas/core/frame.py:11001: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11013: error: Argument 1 of "prod" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11013: note: This violates the Liskov substitution principle
pandas/core/frame.py:11013: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11044: error: Argument 1 of "sem" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11044: note: This violates the Liskov substitution principle
pandas/core/frame.py:11044: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11055: error: Argument 1 of "var" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11055: note: This violates the Liskov substitution principle
pandas/core/frame.py:11055: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11066: error: Argument 1 of "std" is incompatible with supertype "NDFrame"; supertype defines the argument type as "Union[Union[int, Literal['index', 'columns', 'rows']], None, Literal[_NoDefault.no_default]]"  [override]
pandas/core/frame.py:11066: note: This violates the Liskov substitution principle
pandas/core/frame.py:11066: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pandas/core/frame.py:11096: error: Incompatible types in assignment (expression has type "Callable[[Optional[Union[int, Literal['index', 'columns', 'rows']]], bool, bool, int, KwArg(Any)], Any]", base class "NDFrame" defined the type as "Callable[[Union[int, None, Literal['index', 'columns', 'rows', _NoDefault.no_default]], bool, bool, int, KwArg(Any)], Any]")  [assignment]

@jbrockmendel
Copy link
Member Author

updated+green

@mroeschke mroeschke added this to the 2.1 milestone May 25, 2023
@mroeschke mroeschke merged commit d6ee9ad into pandas-dev:main May 25, 2023
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the depr-reductions branch May 25, 2023 16:14
topper-123 pushed a commit to topper-123/pandas that referenced this pull request May 27, 2023
* DEPR: support axis=None in DataFrame reductions

* test, whatsnew

* catch in apply(sum)

* Fix defaults

* catch warnings

* dont check stacklevel

* mypy fixup

* catch warning
topper-123 pushed a commit to topper-123/pandas that referenced this pull request Jun 5, 2023
* DEPR: support axis=None in DataFrame reductions

* test, whatsnew

* catch in apply(sum)

* Fix defaults

* catch warnings

* dont check stacklevel

* mypy fixup

* catch warning
Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
* DEPR: support axis=None in DataFrame reductions

* test, whatsnew

* catch in apply(sum)

* Fix defaults

* catch warnings

* dont check stacklevel

* mypy fixup

* catch warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support axis=None in all reductions
4 participants