Skip to content

Commit 4c6311c

Browse files
committed
Disable M8 in nanops
Closes pandas-dev#24752
1 parent 0c319f5 commit 4c6311c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

pandas/core/nanops.py

+1
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ def nansum(values, axis=None, skipna=True, min_count=0, mask=None):
437437
return _wrap_results(the_sum, dtype)
438438

439439

440+
@disallow('M8')
440441
@bottleneck_switch()
441442
def nanmean(values, axis=None, skipna=True, mask=None):
442443
"""

pandas/tests/frame/test_analytics.py

+16
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,22 @@ 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+
def test_mean_mixed_datetime_numeric(self):
798+
# https://github.com/pandas-dev/pandas/issues/24752
799+
df = pd.DataFrame({"A": [1, 1], "B": [pd.Timestamp('2000')] * 2})
800+
result = df.mean()
801+
expected = pd.Series([1.0], index=['A'])
802+
tm.assert_series_equal(result, expected)
803+
804+
def test_mean_excludeds_datetimes(self):
805+
# https://github.com/pandas-dev/pandas/issues/24752
806+
# Our long-term desired behavior is unclear, but the behavior in
807+
# 0.24.0rc1 was buggy.
808+
df = pd.DataFrame({"A": [pd.Timestamp('2000')] * 2})
809+
result = df.mean()
810+
expected = pd.Series()
811+
tm.assert_series_equal(result, expected)
812+
797813
def test_product(self, float_frame_with_na, float_frame,
798814
float_string_frame):
799815
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)