Skip to content

Commit 6080123

Browse files
TomAugspurgerPingviinituutti
authored andcommitted
Disable M8 in nanops (pandas-dev#24907)
* Disable M8 in nanops Closes pandas-dev#24752
1 parent e9845d9 commit 6080123

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

pandas/core/nanops.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
_get_dtype, is_any_int_dtype, is_bool_dtype, is_complex, is_complex_dtype,
1515
is_datetime64_dtype, is_datetime64tz_dtype, is_datetime_or_timedelta_dtype,
1616
is_float, is_float_dtype, is_integer, is_integer_dtype, is_numeric_dtype,
17-
is_object_dtype, is_scalar, is_timedelta64_dtype)
17+
is_object_dtype, is_scalar, is_timedelta64_dtype, pandas_dtype)
18+
from pandas.core.dtypes.dtypes import DatetimeTZDtype
1819
from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna
1920

2021
import pandas.core.common as com
@@ -57,7 +58,7 @@ class disallow(object):
5758

5859
def __init__(self, *dtypes):
5960
super(disallow, self).__init__()
60-
self.dtypes = tuple(np.dtype(dtype).type for dtype in dtypes)
61+
self.dtypes = tuple(pandas_dtype(dtype).type for dtype in dtypes)
6162

6263
def check(self, obj):
6364
return hasattr(obj, 'dtype') and issubclass(obj.dtype.type,
@@ -437,6 +438,7 @@ def nansum(values, axis=None, skipna=True, min_count=0, mask=None):
437438
return _wrap_results(the_sum, dtype)
438439

439440

441+
@disallow('M8', DatetimeTZDtype)
440442
@bottleneck_switch()
441443
def nanmean(values, axis=None, skipna=True, mask=None):
442444
"""

pandas/tests/frame/test_analytics.py

+19
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,25 @@ def test_mean(self, float_frame_with_na, float_frame, float_string_frame):
794794
check_dates=True)
795795
assert_stat_op_api('mean', float_frame, float_string_frame)
796796

797+
@pytest.mark.parametrize('tz', [None, 'UTC'])
798+
def test_mean_mixed_datetime_numeric(self, tz):
799+
# https://github.com/pandas-dev/pandas/issues/24752
800+
df = pd.DataFrame({"A": [1, 1],
801+
"B": [pd.Timestamp('2000', tz=tz)] * 2})
802+
result = df.mean()
803+
expected = pd.Series([1.0], index=['A'])
804+
tm.assert_series_equal(result, expected)
805+
806+
@pytest.mark.parametrize('tz', [None, 'UTC'])
807+
def test_mean_excludeds_datetimes(self, tz):
808+
# https://github.com/pandas-dev/pandas/issues/24752
809+
# Our long-term desired behavior is unclear, but the behavior in
810+
# 0.24.0rc1 was buggy.
811+
df = pd.DataFrame({"A": [pd.Timestamp('2000', tz=tz)] * 2})
812+
result = df.mean()
813+
expected = pd.Series()
814+
tm.assert_series_equal(result, expected)
815+
797816
def test_product(self, float_frame_with_na, float_frame,
798817
float_string_frame):
799818
assert_stat_op_calc('product', np.prod, float_frame_with_na)

pandas/tests/test_nanops.py

+3
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,9 @@ def prng(self):
971971

972972
class TestDatetime64NaNOps(object):
973973
@pytest.mark.parametrize('tz', [None, 'UTC'])
974+
@pytest.mark.xfail(reason="disabled")
975+
# Enabling mean changes the behavior of DataFrame.mean
976+
# See https://github.com/pandas-dev/pandas/issues/24752
974977
def test_nanmean(self, tz):
975978
dti = pd.date_range('2016-01-01', periods=3, tz=tz)
976979
expected = dti[1]

0 commit comments

Comments
 (0)