Skip to content

Commit

Permalink
Fixing regression in DataFrame.all and DataFrame.any
Browse files Browse the repository at this point in the history
* `bool_only` parameter is supported again
* Commit 36ab8c9 created this regression
  due to a bug in all/any (pandas-dev#23070)
* Reverted the regression and fixed the bug with a condition
* Added tests for `bool_only` parameter
  • Loading branch information
devin-petersohn committed Feb 3, 2019
1 parent f75a220 commit 18f0e4a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.1.rst
Expand Up @@ -56,6 +56,7 @@ Fixed Regressions
- Fixed regression in :class:`Index.intersection` incorrectly sorting the values by default (:issue:`24959`).
- Fixed regression in :func:`merge` when merging an empty ``DataFrame`` with multiple timezone-aware columns on one of the timezone-aware columns (:issue:`25014`).
- Fixed regression in :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` where passing ``None`` failed to remove the axis name (:issue:`25034`)
- Fixed regression in :meth:`DataFrame.all` and :meth:`DataFrame.any` where ``bool_only`` as ``True`` was ignored (:issue:`25101`)

**Timedelta**

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/frame.py
Expand Up @@ -7476,7 +7476,8 @@ def f(x):
if filter_type is None or filter_type == 'numeric':
data = self._get_numeric_data()
elif filter_type == 'bool':
data = self
# GH 25101, # GH 24434
data = self._get_bool_data() if axis == 0 else self
else: # pragma: no cover
msg = ("Generating numeric_only data with filter_type {f}"
"not supported.".format(f=filter_type))
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/frame/test_analytics.py
Expand Up @@ -1442,6 +1442,26 @@ def test_any_datetime(self):
expected = Series([True, True, True, False])
tm.assert_series_equal(result, expected)

def test_any_all_bool_only(self):

# GH 25101
df = DataFrame({"col1": [1,2,3],
"col2": [4,5,6],
"col3": [None, None, None]})

result = df.all(bool_only=True)
expected = Series()
tm.assert_equal(result, expected)

df = DataFrame({"col1": [1,2,3],
"col2": [4,5,6],
"col3": [None, None, None],
"col4":[False, False, True]}

result = df.all(bool_only=True)
expected = Series()
tm.assert_equal(result, expected)

@pytest.mark.parametrize('func, data, expected', [
(np.any, {}, False),
(np.all, {}, True),
Expand Down

0 comments on commit 18f0e4a

Please sign in to comment.