Skip to content

Commit 64d3909

Browse files
jbrockmendelmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#38723: BUG: inconsistency between frame.any/all with dt64 vs dt64tz
1 parent 7550eed commit 64d3909

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
@@ -18,6 +18,8 @@ Fixed regressions
1818
- :meth:`to_csv` created corrupted zip files when there were more rows than ``chunksize`` (issue:`38714`)
1919
- Bug in repr of float-like strings of an ``object`` dtype having trailing 0's truncated after the decimal (:issue:`38708`)
2020
- Fixed regression in :meth:`DataFrame.groupby()` with :class:`Categorical` grouping column not showing unused categories for ``grouped.indices`` (:issue:`38642`)
21+
- Fixed regression in :meth:`DataFrame.any` and :meth:`DataFrame.all` not returning a result for tz-aware ``datetime64`` columns (:issue:`38723`)
22+
-
2123

2224
.. ---------------------------------------------------------------------------
2325

pandas/core/arrays/datetimelike.py

+11
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,17 @@ def floor(self, freq, ambiguous="raise", nonexistent="raise"):
16211621
def ceil(self, freq, ambiguous="raise", nonexistent="raise"):
16221622
return self._round(freq, RoundTo.PLUS_INFTY, ambiguous, nonexistent)
16231623

1624+
# --------------------------------------------------------------
1625+
# Reductions
1626+
1627+
def any(self, *, axis: Optional[int] = None, skipna: bool = True):
1628+
# GH#34479 discussion of desired behavior long-term
1629+
return nanops.nanany(self._ndarray, axis=axis, skipna=skipna, mask=self.isna())
1630+
1631+
def all(self, *, axis: Optional[int] = None, skipna: bool = True):
1632+
# GH#34479 discussion of desired behavior long-term
1633+
return nanops.nanall(self._ndarray, axis=axis, skipna=skipna, mask=self.isna())
1634+
16241635
# --------------------------------------------------------------
16251636
# Frequency Methods
16261637

pandas/tests/frame/test_reductions.py

+4
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,13 @@ def test_any_all_bool_only(self):
10911091
(np.all, {"A": Series([0, 1], dtype=int)}, False),
10921092
(np.any, {"A": Series([0, 1], dtype=int)}, True),
10931093
pytest.param(np.all, {"A": Series([0, 1], dtype="M8[ns]")}, False),
1094+
pytest.param(np.all, {"A": Series([0, 1], dtype="M8[ns, UTC]")}, False),
10941095
pytest.param(np.any, {"A": Series([0, 1], dtype="M8[ns]")}, True),
1096+
pytest.param(np.any, {"A": Series([0, 1], dtype="M8[ns, UTC]")}, True),
10951097
pytest.param(np.all, {"A": Series([1, 2], dtype="M8[ns]")}, True),
1098+
pytest.param(np.all, {"A": Series([1, 2], dtype="M8[ns, UTC]")}, True),
10961099
pytest.param(np.any, {"A": Series([1, 2], dtype="M8[ns]")}, True),
1100+
pytest.param(np.any, {"A": Series([1, 2], dtype="M8[ns, UTC]")}, True),
10971101
pytest.param(np.all, {"A": Series([0, 1], dtype="m8[ns]")}, False),
10981102
pytest.param(np.any, {"A": Series([0, 1], dtype="m8[ns]")}, True),
10991103
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)