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)#21486jorisvandenbossche merged 10 commits intopandas-dev:masterfrom
Conversation
Accepts axis=None as reduce all dims
|
|
||
|
|
||
| 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: |
| B False | ||
| dtype: bool | ||
|
|
||
| With pandas 0.23.2, that will correctly return False. |
There was a problem hiding this comment.
maybe add ", as it did before with numpy < 1.15" ?
| ---------- | ||
| 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.
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 ?
| """ | ||
| delegate = self._values | ||
| if axis is None: | ||
| axis = self._stat_axis_number |
There was a problem hiding this comment.
Why is this still needed?
There was a problem hiding this comment.
Can you have a look at this one?
There was a problem hiding this comment.
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.
Shouldn't there be an override of this in case of Panel? (which is the only case where the stat_axis differs from 0)
| values = self.values | ||
| result = f(values) | ||
|
|
||
| if (filter_type == 'bool' and values.dtype.kind == 'O' and |
| 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.
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 --diffThis 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.