Skip to content

BUG: DataFrame.any with axis=1 and bool_only=True #36106

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

Merged
merged 3 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Timezones
Numeric
^^^^^^^
- Bug in :func:`to_numeric` where float precision was incorrect (:issue:`31364`)
- Bug in :meth:`DataFrame.any` with ``axis=1`` and ``bool_only=True`` ignoring the ``bool_only`` keyword (:issue:`32432`)
-

Conversion
Expand Down
14 changes: 5 additions & 9 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8639,15 +8639,12 @@ def func(values):
else:
return op(values, axis=axis, skipna=skipna, **kwds)

def _get_data(axis_matters: bool) -> DataFrame:
def _get_data() -> DataFrame:
if filter_type is None:
data = self._get_numeric_data()
elif filter_type == "bool":
if axis_matters:
# GH#25101, GH#24434
data = self._get_bool_data() if axis == 0 else self
else:
data = self._get_bool_data()
# GH#25101, GH#24434
data = self._get_bool_data()
else: # pragma: no cover
msg = (
f"Generating numeric_only data with filter_type {filter_type} "
Expand All @@ -8659,7 +8656,7 @@ def _get_data(axis_matters: bool) -> DataFrame:
if numeric_only is not None:
df = self
if numeric_only is True:
df = _get_data(axis_matters=True)
df = _get_data()
if axis == 1:
df = df.T
axis = 0
Expand Down Expand Up @@ -8720,8 +8717,7 @@ def blk_func(values):
except TypeError:
# e.g. in nanops trying to convert strs to float

# TODO: why doesnt axis matter here?
data = _get_data(axis_matters=False)
data = _get_data()
labels = data._get_agg_axis(axis)

values = data.values
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,13 @@ def test_all_any_boolean(self):
tm.assert_series_equal(s.all(level=0), Series([False, True, False]))
tm.assert_series_equal(s.any(level=0), Series([False, True, True]))

def test_any_axis1_bool_only(self):
# GH#32432
df = pd.DataFrame({"A": [True, False], "B": [1, 2]})
result = df.any(axis=1, bool_only=True)
expected = pd.Series([True, False])
tm.assert_series_equal(result, expected)

def test_timedelta64_analytics(self):

# index min/max
Expand Down