Skip to content

Commit a09259b

Browse files
authored
BUG: DataFrame.any with axis=1 and bool_only=True (#36106)
1 parent 03c7040 commit a09259b

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ Timezones
246246
Numeric
247247
^^^^^^^
248248
- Bug in :func:`to_numeric` where float precision was incorrect (:issue:`31364`)
249+
- Bug in :meth:`DataFrame.any` with ``axis=1`` and ``bool_only=True`` ignoring the ``bool_only`` keyword (:issue:`32432`)
249250
-
250251

251252
Conversion

pandas/core/frame.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -8639,15 +8639,12 @@ def func(values):
86398639
else:
86408640
return op(values, axis=axis, skipna=skipna, **kwds)
86418641

8642-
def _get_data(axis_matters: bool) -> DataFrame:
8642+
def _get_data() -> DataFrame:
86438643
if filter_type is None:
86448644
data = self._get_numeric_data()
86458645
elif filter_type == "bool":
8646-
if axis_matters:
8647-
# GH#25101, GH#24434
8648-
data = self._get_bool_data() if axis == 0 else self
8649-
else:
8650-
data = self._get_bool_data()
8646+
# GH#25101, GH#24434
8647+
data = self._get_bool_data()
86518648
else: # pragma: no cover
86528649
msg = (
86538650
f"Generating numeric_only data with filter_type {filter_type} "
@@ -8659,7 +8656,7 @@ def _get_data(axis_matters: bool) -> DataFrame:
86598656
if numeric_only is not None:
86608657
df = self
86618658
if numeric_only is True:
8662-
df = _get_data(axis_matters=True)
8659+
df = _get_data()
86638660
if axis == 1:
86648661
df = df.T
86658662
axis = 0
@@ -8720,8 +8717,7 @@ def blk_func(values):
87208717
except TypeError:
87218718
# e.g. in nanops trying to convert strs to float
87228719

8723-
# TODO: why doesnt axis matter here?
8724-
data = _get_data(axis_matters=False)
8720+
data = _get_data()
87258721
labels = data._get_agg_axis(axis)
87268722

87278723
values = data.values

pandas/tests/reductions/test_reductions.py

+7
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,13 @@ def test_all_any_boolean(self):
914914
tm.assert_series_equal(s.all(level=0), Series([False, True, False]))
915915
tm.assert_series_equal(s.any(level=0), Series([False, True, True]))
916916

917+
def test_any_axis1_bool_only(self):
918+
# GH#32432
919+
df = pd.DataFrame({"A": [True, False], "B": [1, 2]})
920+
result = df.any(axis=1, bool_only=True)
921+
expected = pd.Series([True, False])
922+
tm.assert_series_equal(result, expected)
923+
917924
def test_timedelta64_analytics(self):
918925

919926
# index min/max

0 commit comments

Comments
 (0)