From d25e9067ab98e2acc5982a4dfaee34d17d61f17d Mon Sep 17 00:00:00 2001 From: makbigc Date: Sun, 23 Dec 2018 13:37:40 +0800 Subject: [PATCH 01/10] Remove is_bool in function get_bool_data --- pandas/core/internals/managers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index f1372a1fe2f51..4990d8576812f 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -640,7 +640,7 @@ def get_bool_data(self, copy=False): Whether to copy the blocks """ self._consolidate_inplace() - return self.combine([b for b in self.blocks if b.is_bool], copy) + return self.combine([b for b in self.blocks], copy) def get_numeric_data(self, copy=False): """ From 8546b526dedc970d7bafae65a8222708dd900328 Mon Sep 17 00:00:00 2001 From: makbigc Date: Sun, 23 Dec 2018 22:47:16 +0800 Subject: [PATCH 02/10] Add two new methods _get_data and get_data --- pandas/core/generic.py | 3 +++ pandas/core/internals/managers.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index eb14a26e75a9c..bc4012bd3ed37 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5179,6 +5179,9 @@ def _check_inplace_setting(self, value): return True + def _get_data(self): + return self._constructor(self._data.get_data()).__finalize__(self) + def _get_numeric_data(self): return self._constructor( self._data.get_numeric_data()).__finalize__(self) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 4990d8576812f..871d69ec266a1 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -632,7 +632,7 @@ def is_view(self): return False - def get_bool_data(self, copy=False): + def get_data(self, copy=False): """ Parameters ---------- @@ -642,6 +642,16 @@ def get_bool_data(self, copy=False): self._consolidate_inplace() return self.combine([b for b in self.blocks], copy) + def get_bool_data(self, copy=False): + """ + Parameters + ---------- + copy : boolean, default False + Whether to copy the blocks + """ + self._consolidate_inplace() + return self.combine([b for b in self.blocks if b.is_bool], copy) + def get_numeric_data(self, copy=False): """ Parameters From dea4efe736cea8508fb3c550a850fbf90179a25e Mon Sep 17 00:00:00 2001 From: makbigc Date: Sun, 23 Dec 2018 22:50:56 +0800 Subject: [PATCH 03/10] Change the dispatch to the new method --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a34a34186cf45..c8ea97116ed34 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7291,7 +7291,7 @@ def f(x): if filter_type is None or filter_type == 'numeric': data = self._get_numeric_data() elif filter_type == 'bool': - data = self._get_bool_data() + data = self._get_data() else: # pragma: no cover msg = ("Generating numeric_only data with filter_type {f}" "not supported.".format(f=filter_type)) From 12e374102f161a4b3d484ed31cb08a6a4c934225 Mon Sep 17 00:00:00 2001 From: makbigc Date: Sun, 23 Dec 2018 22:51:20 +0800 Subject: [PATCH 04/10] Add new test --- pandas/tests/frame/test_analytics.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 6f68828b94a84..781b3a1e65aae 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1394,6 +1394,23 @@ def test_any_all_extra(self): # df.any(1, bool_only=True) # df.all(1, bool_only=True) + def test_any_datetime(self): + + # GH 23070 + float_data = [1, np.nan, 3, np.nan] + datetime_data = [pd.Timestamp('1960-02-15'), + pd.Timestamp('1960-02-16'), + pd.NaT, + pd.NaT] + df = DataFrame({ + "A": float_data, + "B": datetime_data + }) + + result = df.any(1) + expected = Series([True, True, True, False]) + tm.assert_series_equal(result, expected) + @pytest.mark.parametrize('func, data, expected', [ (np.any, {}, False), (np.all, {}, True), From e4d5acb7ec8dddb0b549d18c9c1f2cf1cf41ba83 Mon Sep 17 00:00:00 2001 From: makbigc Date: Wed, 26 Dec 2018 22:51:25 +0800 Subject: [PATCH 05/10] Add whatsnew --- doc/source/whatsnew/v0.24.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index affef80571fce..d1ce865f02a46 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1412,6 +1412,7 @@ Timezones - Bug in :class:`Timestamp` constructor where a ``dateutil.tz.tzutc`` timezone passed with a ``datetime.datetime`` argument would be converted to a ``pytz.UTC`` timezone (:issue:`23807`) - Bug in :func:`to_datetime` where ``utc=True`` was not respected when specifying a ``unit`` and ``errors='ignore'`` (:issue:`23758`) - Bug in :func:`to_datetime` where ``utc=True`` was not respected when passing a :class:`Timestamp` (:issue:`24415`) +- Bug in :meth:`DataFrame.any` returns wrong value when the axis is one and the data is of datetime type (:issue:`23070`) Offsets ^^^^^^^ From 0609fba4a05818bc6e1568065b79fba7afbd4149 Mon Sep 17 00:00:00 2001 From: makbigc Date: Thu, 27 Dec 2018 20:19:13 +0800 Subject: [PATCH 06/10] Assign self to data and remove _get_data and get_data --- pandas/core/frame.py | 2 +- pandas/core/generic.py | 3 --- pandas/core/internals/managers.py | 10 ---------- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c8ea97116ed34..99ae551d3c55b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7291,7 +7291,7 @@ def f(x): if filter_type is None or filter_type == 'numeric': data = self._get_numeric_data() elif filter_type == 'bool': - data = self._get_data() + data = self else: # pragma: no cover msg = ("Generating numeric_only data with filter_type {f}" "not supported.".format(f=filter_type)) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index bc4012bd3ed37..eb14a26e75a9c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5179,9 +5179,6 @@ def _check_inplace_setting(self, value): return True - def _get_data(self): - return self._constructor(self._data.get_data()).__finalize__(self) - def _get_numeric_data(self): return self._constructor( self._data.get_numeric_data()).__finalize__(self) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 871d69ec266a1..f1372a1fe2f51 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -632,16 +632,6 @@ def is_view(self): return False - def get_data(self, copy=False): - """ - Parameters - ---------- - copy : boolean, default False - Whether to copy the blocks - """ - self._consolidate_inplace() - return self.combine([b for b in self.blocks], copy) - def get_bool_data(self, copy=False): """ Parameters From 686e389627b08bfecaae7973355ca24f2fdb13e7 Mon Sep 17 00:00:00 2001 From: makbigc Date: Thu, 27 Dec 2018 20:57:31 +0800 Subject: [PATCH 07/10] Remove the comment block in test_any_all_extra --- pandas/tests/frame/test_analytics.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 781b3a1e65aae..affa60b6f664a 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1374,26 +1374,6 @@ def test_any_all_extra(self): result = df[['C']].all(axis=None).item() assert result is True - # skip pathological failure cases - # class CantNonzero(object): - - # def __nonzero__(self): - # raise ValueError - - # df[4] = CantNonzero() - - # it works! - # df.any(1) - # df.all(1) - # df.any(1, bool_only=True) - # df.all(1, bool_only=True) - - # df[4][4] = np.nan - # df.any(1) - # df.all(1) - # df.any(1, bool_only=True) - # df.all(1, bool_only=True) - def test_any_datetime(self): # GH 23070 From 1c7d5aa3a57b8a9df843d41a0fdbc58aa37d4adc Mon Sep 17 00:00:00 2001 From: makbigc Date: Sun, 30 Dec 2018 00:36:13 +0800 Subject: [PATCH 08/10] Remove class NonzeroFail --- pandas/tests/frame/test_analytics.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index affa60b6f664a..73ea2c679913c 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -228,13 +228,6 @@ def assert_bool_op_api(opname, bool_frame_with_na, float_string_frame, getattr(mixed, opname)(axis=0) getattr(mixed, opname)(axis=1) - class NonzeroFail(object): - - def __nonzero__(self): - raise ValueError - - mixed['_nonzero_fail_'] = NonzeroFail() - if has_bool_only: getattr(mixed, opname)(axis=0, bool_only=True) getattr(mixed, opname)(axis=1, bool_only=True) From 24885c99be901a8b80ae6fbbce4f4f8409840e42 Mon Sep 17 00:00:00 2001 From: makbigc Date: Sun, 30 Dec 2018 00:38:40 +0800 Subject: [PATCH 09/10] Change v0.24.0.rst --- doc/source/whatsnew/v0.24.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index d1ce865f02a46..ffa13804f9397 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1412,7 +1412,7 @@ Timezones - Bug in :class:`Timestamp` constructor where a ``dateutil.tz.tzutc`` timezone passed with a ``datetime.datetime`` argument would be converted to a ``pytz.UTC`` timezone (:issue:`23807`) - Bug in :func:`to_datetime` where ``utc=True`` was not respected when specifying a ``unit`` and ``errors='ignore'`` (:issue:`23758`) - Bug in :func:`to_datetime` where ``utc=True`` was not respected when passing a :class:`Timestamp` (:issue:`24415`) -- Bug in :meth:`DataFrame.any` returns wrong value when the axis is one and the data is of datetime type (:issue:`23070`) +- Bug in :meth:`DataFrame.any` returns wrong value when ``axis=1`` and the data is of datetimelike type (:issue:`23070`) Offsets ^^^^^^^ From 9007017fcac882e269a01f0a631d6a37c3d07faa Mon Sep 17 00:00:00 2001 From: Mak Sze Chun Date: Sun, 30 Dec 2018 14:24:57 +0800 Subject: [PATCH 10/10] Update v0.24.0.rst --- doc/source/whatsnew/v0.24.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index ffa13804f9397..8568230dd07b8 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -1412,7 +1412,7 @@ Timezones - Bug in :class:`Timestamp` constructor where a ``dateutil.tz.tzutc`` timezone passed with a ``datetime.datetime`` argument would be converted to a ``pytz.UTC`` timezone (:issue:`23807`) - Bug in :func:`to_datetime` where ``utc=True`` was not respected when specifying a ``unit`` and ``errors='ignore'`` (:issue:`23758`) - Bug in :func:`to_datetime` where ``utc=True`` was not respected when passing a :class:`Timestamp` (:issue:`24415`) -- Bug in :meth:`DataFrame.any` returns wrong value when ``axis=1`` and the data is of datetimelike type (:issue:`23070`) +- Bug in :meth:`DataFrame.any` returns wrong value when ``axis=1`` and the data is of datetimelike type (:issue:`23070`) Offsets ^^^^^^^