Skip to content

Commit 18f0e4a

Browse files
Fixing regression in DataFrame.all and DataFrame.any
* `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
1 parent f75a220 commit 18f0e4a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

doc/source/whatsnew/v0.24.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Fixed Regressions
5656
- Fixed regression in :class:`Index.intersection` incorrectly sorting the values by default (:issue:`24959`).
5757
- Fixed regression in :func:`merge` when merging an empty ``DataFrame`` with multiple timezone-aware columns on one of the timezone-aware columns (:issue:`25014`).
5858
- Fixed regression in :meth:`Series.rename_axis` and :meth:`DataFrame.rename_axis` where passing ``None`` failed to remove the axis name (:issue:`25034`)
59+
- Fixed regression in :meth:`DataFrame.all` and :meth:`DataFrame.any` where ``bool_only`` as ``True`` was ignored (:issue:`25101`)
5960

6061
**Timedelta**
6162

pandas/core/frame.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7476,7 +7476,8 @@ def f(x):
74767476
if filter_type is None or filter_type == 'numeric':
74777477
data = self._get_numeric_data()
74787478
elif filter_type == 'bool':
7479-
data = self
7479+
# GH 25101, # GH 24434
7480+
data = self._get_bool_data() if axis == 0 else self
74807481
else: # pragma: no cover
74817482
msg = ("Generating numeric_only data with filter_type {f}"
74827483
"not supported.".format(f=filter_type))

pandas/tests/frame/test_analytics.py

+20
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,26 @@ def test_any_datetime(self):
14421442
expected = Series([True, True, True, False])
14431443
tm.assert_series_equal(result, expected)
14441444

1445+
def test_any_all_bool_only(self):
1446+
1447+
# GH 25101
1448+
df = DataFrame({"col1": [1,2,3],
1449+
"col2": [4,5,6],
1450+
"col3": [None, None, None]})
1451+
1452+
result = df.all(bool_only=True)
1453+
expected = Series()
1454+
tm.assert_equal(result, expected)
1455+
1456+
df = DataFrame({"col1": [1,2,3],
1457+
"col2": [4,5,6],
1458+
"col3": [None, None, None],
1459+
"col4":[False, False, True]}
1460+
1461+
result = df.all(bool_only=True)
1462+
expected = Series()
1463+
tm.assert_equal(result, expected)
1464+
14451465
@pytest.mark.parametrize('func, data, expected', [
14461466
(np.any, {}, False),
14471467
(np.all, {}, True),

0 commit comments

Comments
 (0)