Skip to content

REF: dont support dt64tz in nanmean #37658

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

Merged
merged 3 commits into from
Nov 9, 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
10 changes: 3 additions & 7 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add an assert here as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you want to assert?

pass
Expand All @@ -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]")
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/test_nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]:
Expand Down