Skip to content

Commit 3f3b64d

Browse files
jbrockmendelluckyvs1
authored andcommitted
BUG: inconsistency between frame.any/all with dt64 vs dt64tz (pandas-dev#38723)
1 parent 00ae71c commit 3f3b64d

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

doc/source/whatsnew/v1.2.1.rst

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Fixed regressions
1919
- Fixed a regression in ``groupby().rolling()`` where :class:`MultiIndex` levels were dropped (:issue:`38523`)
2020
- Bug in repr of float-like strings of an ``object`` dtype having trailing 0's truncated after the decimal (:issue:`38708`)
2121
- Fixed regression in :meth:`DataFrame.groupby()` with :class:`Categorical` grouping column not showing unused categories for ``grouped.indices`` (:issue:`38642`)
22+
- Fixed regression in :meth:`DataFrame.any` and :meth:`DataFrame.all` not returning a result for tz-aware ``datetime64`` columns (:issue:`38723`)
23+
-
2224

2325
.. ---------------------------------------------------------------------------
2426

pandas/core/arrays/datetimelike.py

+11
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,17 @@ def floor(self, freq, ambiguous="raise", nonexistent="raise"):
16401640
def ceil(self, freq, ambiguous="raise", nonexistent="raise"):
16411641
return self._round(freq, RoundTo.PLUS_INFTY, ambiguous, nonexistent)
16421642

1643+
# --------------------------------------------------------------
1644+
# Reductions
1645+
1646+
def any(self, *, axis: Optional[int] = None, skipna: bool = True):
1647+
# GH#34479 discussion of desired behavior long-term
1648+
return nanops.nanany(self._ndarray, axis=axis, skipna=skipna, mask=self.isna())
1649+
1650+
def all(self, *, axis: Optional[int] = None, skipna: bool = True):
1651+
# GH#34479 discussion of desired behavior long-term
1652+
return nanops.nanall(self._ndarray, axis=axis, skipna=skipna, mask=self.isna())
1653+
16431654
# --------------------------------------------------------------
16441655
# Frequency Methods
16451656

pandas/tests/frame/test_reductions.py

+4
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,13 @@ def test_any_all_bool_only(self):
10971097
(np.all, {"A": Series([0, 1], dtype=int)}, False),
10981098
(np.any, {"A": Series([0, 1], dtype=int)}, True),
10991099
pytest.param(np.all, {"A": Series([0, 1], dtype="M8[ns]")}, False),
1100+
pytest.param(np.all, {"A": Series([0, 1], dtype="M8[ns, UTC]")}, False),
11001101
pytest.param(np.any, {"A": Series([0, 1], dtype="M8[ns]")}, True),
1102+
pytest.param(np.any, {"A": Series([0, 1], dtype="M8[ns, UTC]")}, True),
11011103
pytest.param(np.all, {"A": Series([1, 2], dtype="M8[ns]")}, True),
1104+
pytest.param(np.all, {"A": Series([1, 2], dtype="M8[ns, UTC]")}, True),
11021105
pytest.param(np.any, {"A": Series([1, 2], dtype="M8[ns]")}, True),
1106+
pytest.param(np.any, {"A": Series([1, 2], dtype="M8[ns, UTC]")}, True),
11031107
pytest.param(np.all, {"A": Series([0, 1], dtype="m8[ns]")}, False),
11041108
pytest.param(np.any, {"A": Series([0, 1], dtype="m8[ns]")}, True),
11051109
pytest.param(np.all, {"A": Series([1, 2], dtype="m8[ns]")}, True),

pandas/tests/reductions/test_reductions.py

+43
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Timedelta,
1818
TimedeltaIndex,
1919
Timestamp,
20+
date_range,
2021
isna,
2122
timedelta_range,
2223
to_timedelta,
@@ -923,6 +924,48 @@ def test_any_axis1_bool_only(self):
923924
expected = Series([True, False])
924925
tm.assert_series_equal(result, expected)
925926

927+
def test_any_all_datetimelike(self):
928+
# GH#38723 these may not be the desired long-term behavior (GH#34479)
929+
# but in the interim should be internally consistent
930+
dta = date_range("1995-01-02", periods=3)._data
931+
ser = Series(dta)
932+
df = DataFrame(ser)
933+
934+
assert dta.all()
935+
assert dta.any()
936+
937+
assert ser.all()
938+
assert ser.any()
939+
940+
assert df.any().all()
941+
assert df.all().all()
942+
943+
dta = dta.tz_localize("UTC")
944+
ser = Series(dta)
945+
df = DataFrame(ser)
946+
947+
assert dta.all()
948+
assert dta.any()
949+
950+
assert ser.all()
951+
assert ser.any()
952+
953+
assert df.any().all()
954+
assert df.all().all()
955+
956+
tda = dta - dta[0]
957+
ser = Series(tda)
958+
df = DataFrame(ser)
959+
960+
assert tda.any()
961+
assert not tda.all()
962+
963+
assert ser.any()
964+
assert not ser.all()
965+
966+
assert df.any().all()
967+
assert not df.all().any()
968+
926969
def test_timedelta64_analytics(self):
927970

928971
# index min/max

0 commit comments

Comments
 (0)