Skip to content

Commit a2696fe

Browse files
authored
REF: dont support dt64tz in nanmean (#37658)
1 parent dbee8fa commit a2696fe

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

pandas/core/nanops.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pandas._config import get_option
1010

11-
from pandas._libs import NaT, Timedelta, Timestamp, iNaT, lib
11+
from pandas._libs import NaT, Timedelta, iNaT, lib
1212
from pandas._typing import ArrayLike, Dtype, DtypeObj, F, Scalar
1313
from pandas.compat._optional import import_optional_dependency
1414

@@ -330,7 +330,7 @@ def _na_ok_dtype(dtype: DtypeObj) -> bool:
330330
return not issubclass(dtype.type, np.integer)
331331

332332

333-
def _wrap_results(result, dtype: DtypeObj, fill_value=None):
333+
def _wrap_results(result, dtype: np.dtype, fill_value=None):
334334
""" wrap our results if needed """
335335
if result is NaT:
336336
pass
@@ -340,15 +340,11 @@ def _wrap_results(result, dtype: DtypeObj, fill_value=None):
340340
# GH#24293
341341
fill_value = iNaT
342342
if not isinstance(result, np.ndarray):
343-
tz = getattr(dtype, "tz", None)
344343
assert not isna(fill_value), "Expected non-null fill_value"
345344
if result == fill_value:
346345
result = np.nan
347346

348-
if tz is not None:
349-
# we get here e.g. via nanmean when we call it on a DTA[tz]
350-
result = Timestamp(result, tz=tz)
351-
elif isna(result):
347+
if isna(result):
352348
result = np.datetime64("NaT", "ns")
353349
else:
354350
result = np.int64(result).view("datetime64[ns]")

pandas/tests/test_nanops.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -988,11 +988,10 @@ def prng(self):
988988

989989

990990
class TestDatetime64NaNOps:
991-
@pytest.mark.parametrize("tz", [None, "UTC"])
992991
# Enabling mean changes the behavior of DataFrame.mean
993992
# See https://github.com/pandas-dev/pandas/issues/24752
994-
def test_nanmean(self, tz):
995-
dti = pd.date_range("2016-01-01", periods=3, tz=tz)
993+
def test_nanmean(self):
994+
dti = pd.date_range("2016-01-01", periods=3)
996995
expected = dti[1]
997996

998997
for obj in [dti, DatetimeArray(dti), Series(dti)]:

0 commit comments

Comments
 (0)