diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 6dc05c23c026f..cfb02e5b1e987 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -8,7 +8,7 @@ from pandas._config import get_option -from pandas._libs import NaT, Timedelta, Timestamp, iNaT, lib +from pandas._libs import NaT, Timedelta, iNaT, lib from pandas._typing import ArrayLike, Dtype, DtypeObj, F, Scalar from pandas.compat._optional import import_optional_dependency @@ -330,7 +330,7 @@ def _na_ok_dtype(dtype: DtypeObj) -> bool: return not issubclass(dtype.type, np.integer) -def _wrap_results(result, dtype: DtypeObj, fill_value=None): +def _wrap_results(result, dtype: np.dtype, fill_value=None): """ wrap our results if needed """ if result is NaT: pass @@ -340,15 +340,11 @@ def _wrap_results(result, dtype: DtypeObj, fill_value=None): # GH#24293 fill_value = iNaT if not isinstance(result, np.ndarray): - tz = getattr(dtype, "tz", None) assert not isna(fill_value), "Expected non-null fill_value" if result == fill_value: result = np.nan - if tz is not None: - # we get here e.g. via nanmean when we call it on a DTA[tz] - result = Timestamp(result, tz=tz) - elif isna(result): + if isna(result): result = np.datetime64("NaT", "ns") else: result = np.int64(result).view("datetime64[ns]") diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index 458fba2e13b0f..359a7eecf6f7b 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -988,11 +988,10 @@ def prng(self): class TestDatetime64NaNOps: - @pytest.mark.parametrize("tz", [None, "UTC"]) # Enabling mean changes the behavior of DataFrame.mean # See https://github.com/pandas-dev/pandas/issues/24752 - def test_nanmean(self, tz): - dti = pd.date_range("2016-01-01", periods=3, tz=tz) + def test_nanmean(self): + dti = pd.date_range("2016-01-01", periods=3) expected = dti[1] for obj in [dti, DatetimeArray(dti), Series(dti)]: