Skip to content
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

BUG: inconsistency between frame.any/all with dt64 vs dt64tz #38723

Merged
merged 13 commits into from
Dec 30, 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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Fixed regressions
- Fixed a regression in ``groupby().rolling()`` where :class:`MultiIndex` levels were dropped (:issue:`38523`)
- Bug in repr of float-like strings of an ``object`` dtype having trailing 0's truncated after the decimal (:issue:`38708`)
- Fixed regression in :meth:`DataFrame.groupby()` with :class:`Categorical` grouping column not showing unused categories for ``grouped.indices`` (:issue:`38642`)
- Fixed regression in :meth:`DataFrame.any` and :meth:`DataFrame.all` not returning a result for tz-aware ``datetime64`` columns (:issue:`38723`)
-

.. ---------------------------------------------------------------------------

Expand Down
11 changes: 11 additions & 0 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,17 @@ def floor(self, freq, ambiguous="raise", nonexistent="raise"):
def ceil(self, freq, ambiguous="raise", nonexistent="raise"):
return self._round(freq, RoundTo.PLUS_INFTY, ambiguous, nonexistent)

# --------------------------------------------------------------
# Reductions

def any(self, *, axis: Optional[int] = None, skipna: bool = True):
# GH#34479 discussion of desired behavior long-term
return nanops.nanany(self._ndarray, axis=axis, skipna=skipna, mask=self.isna())

def all(self, *, axis: Optional[int] = None, skipna: bool = True):
# GH#34479 discussion of desired behavior long-term
return nanops.nanall(self._ndarray, axis=axis, skipna=skipna, mask=self.isna())

# --------------------------------------------------------------
# Frequency Methods

Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,13 @@ def test_any_all_bool_only(self):
(np.all, {"A": Series([0, 1], dtype=int)}, False),
(np.any, {"A": Series([0, 1], dtype=int)}, True),
pytest.param(np.all, {"A": Series([0, 1], dtype="M8[ns]")}, False),
pytest.param(np.all, {"A": Series([0, 1], dtype="M8[ns, UTC]")}, False),
pytest.param(np.any, {"A": Series([0, 1], dtype="M8[ns]")}, True),
pytest.param(np.any, {"A": Series([0, 1], dtype="M8[ns, UTC]")}, True),
pytest.param(np.all, {"A": Series([1, 2], dtype="M8[ns]")}, True),
pytest.param(np.all, {"A": Series([1, 2], dtype="M8[ns, UTC]")}, True),
pytest.param(np.any, {"A": Series([1, 2], dtype="M8[ns]")}, True),
pytest.param(np.any, {"A": Series([1, 2], dtype="M8[ns, UTC]")}, True),
pytest.param(np.all, {"A": Series([0, 1], dtype="m8[ns]")}, False),
pytest.param(np.any, {"A": Series([0, 1], dtype="m8[ns]")}, True),
pytest.param(np.all, {"A": Series([1, 2], dtype="m8[ns]")}, True),
Expand Down
43 changes: 43 additions & 0 deletions pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Timedelta,
TimedeltaIndex,
Timestamp,
date_range,
isna,
timedelta_range,
to_timedelta,
Expand Down Expand Up @@ -923,6 +924,48 @@ def test_any_axis1_bool_only(self):
expected = Series([True, False])
tm.assert_series_equal(result, expected)

def test_any_all_datetimelike(self):
# GH#38723 these may not be the desired long-term behavior (GH#34479)
# but in the interim should be internally consistent
dta = date_range("1995-01-02", periods=3)._data
ser = Series(dta)
df = DataFrame(ser)

assert dta.all()
assert dta.any()

assert ser.all()
assert ser.any()

assert df.any().all()
assert df.all().all()

dta = dta.tz_localize("UTC")
ser = Series(dta)
df = DataFrame(ser)

assert dta.all()
assert dta.any()

assert ser.all()
assert ser.any()

assert df.any().all()
assert df.all().all()

tda = dta - dta[0]
ser = Series(tda)
df = DataFrame(ser)

assert tda.any()
assert not tda.all()

assert ser.any()
assert not ser.all()

assert df.any().all()
assert not df.all().any()

def test_timedelta64_analytics(self):

# index min/max
Expand Down