-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
API/COMPAT: support axis=None for logical reduction (reduce over all axes) #21486
API/COMPAT: support axis=None for logical reduction (reduce over all axes) #21486
Conversation
Accepts axis=None as reduce all dims
doc/source/whatsnew/v0.23.2.txt
Outdated
|
||
|
||
This also provides compatibility with NumPy 1.15, which now dispatches to ``DataFrame.all``. | ||
With NumPy 1.15 and pandas 0.23.1 or earlier, :func:`numpy.all` will not reduce over every axis: |
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.
not -> no longer ?
doc/source/whatsnew/v0.23.2.txt
Outdated
B False | ||
dtype: bool | ||
|
||
With pandas 0.23.2, that will correctly return False. |
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.
maybe add ", as it did before with numpy < 1.15" ?
pandas/core/generic.py
Outdated
@@ -9055,8 +9057,16 @@ def _doc_parms(cls): | |||
|
|||
Parameters | |||
---------- | |||
axis : int, default 0 | |||
Select the axis which can be 0 for indices and 1 for columns. | |||
axis : {None, 0 or 'index', 1 or 'columns'}, default None |
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.
I don't think default None
is correct?
The default for our method is still 0? It's only when doing np.all(..)
that we respect the axis=None
?
pandas/core/series.py
Outdated
@@ -3238,6 +3238,8 @@ def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None, | |||
|
|||
""" | |||
delegate = self._values | |||
if axis is None: | |||
axis = self._stat_axis_number |
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.
Why is this still needed?
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.
Can you have a look at this one?
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.
Sorry, missed this earlier. We still call self._get_axis_number(axis)
to validate that the user passed axis
is correct. I'll modify things to be clearer.
if skipna is None: | ||
skipna = True | ||
if axis is None: | ||
axis = self._stat_axis_number |
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.
Shouldn't there be an override of this in case of Panel? (which is the only case where the stat_axis differs from 0)
pandas/core/frame.py
Outdated
@@ -6859,6 +6864,13 @@ def f(x): | |||
try: | |||
values = self.values | |||
result = f(values) | |||
|
|||
if (filter_type == 'bool' and values.dtype.kind == 'O' and |
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.
use is_object_dtype
@@ -1159,11 +1159,34 @@ def test_any_all(self): | |||
self._check_bool_op('any', np.any, has_skipna=True, has_bool_only=True) | |||
self._check_bool_op('all', np.all, has_skipna=True, has_bool_only=True) | |||
|
|||
df = DataFrame(randn(10, 4)) > 0 |
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.
I would make a new test function here
Tests are still failing: |
Codecov Report
@@ Coverage Diff @@
## master #21486 +/- ##
==========================================
- Coverage 91.92% 91.9% -0.03%
==========================================
Files 153 153
Lines 49563 49562 -1
==========================================
- Hits 45559 45548 -11
- Misses 4004 4014 +10
Continue to review full report at Codecov.
|
I think you need to change
in otherwise lgtm. |
Good catch. I've removed the xfail entirely, since I think it will pass on all versions now. |
…axes) (pandas-dev#21486) * Compat with NumPy 1.15 logical func * Accepts axis=None as reduce all dims (cherry picked from commit f7ed7f8)
…axes) (pandas-dev#21486) * Compat with NumPy 1.15 logical func * Accepts axis=None as reduce all dims
git diff upstream/master -u -- "*.py" | flake8 --diff
This is the minimal fix, just to get np.all / np.any working again.
Some followup items:
DataFrame.values
, which isn't necessary for logical reductions.