From c42526ff523a1032ab922c049f411494491f7faa Mon Sep 17 00:00:00 2001 From: MeeseeksMachine <39504233+meeseeksmachine@users.noreply.github.com> Date: Mon, 4 Feb 2019 12:58:19 -0800 Subject: [PATCH] Backport PR #25102: BUG: Fixing regression in DataFrame.all and DataFrame.any with bool_only=True (#25140) --- doc/source/whatsnew/v0.24.2.rst | 4 +--- pandas/core/frame.py | 3 ++- pandas/tests/frame/test_analytics.py | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index 316fc21c126ac..a047ad46e4887 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -20,9 +20,7 @@ including other versions of pandas. Fixed Regressions ^^^^^^^^^^^^^^^^^ -- -- -- +- Fixed regression in :meth:`DataFrame.all` and :meth:`DataFrame.any` where ``bool_only=True`` was ignored (:issue:`25101`) .. _whatsnew_0242.enhancements: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8fbfc8a06c1d0..da638e24dfce5 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7455,7 +7455,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)) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 386e5f57617cf..456af34e74956 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -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(dtype=np.bool) + tm.assert_series_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({"col4": False}) + tm.assert_series_equal(result, expected) + @pytest.mark.parametrize('func, data, expected', [ (np.any, {}, False), (np.all, {}, True),