Skip to content

Commit e87f5b8

Browse files
committed
Merge branch 'master' of https://github.com/pandas-dev/pandas into tana
2 parents 91088c2 + 5761e35 commit e87f5b8

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
@@ -806,6 +806,25 @@ def test_mean(self, float_frame_with_na):
806806
def test_product(self, float_frame_with_na):
807807
assert_stat_op_calc('product', np.prod, float_frame_with_na)
808808

809+
@pytest.mark.parametrize('tz', [None, 'UTC'])
810+
def test_mean_mixed_datetime_numeric(self, tz):
811+
# https://github.com/pandas-dev/pandas/issues/24752
812+
df = pd.DataFrame({"A": [1, 1],
813+
"B": [pd.Timestamp('2000', tz=tz)] * 2})
814+
result = df.mean()
815+
expected = pd.Series([1.0], index=['A'])
816+
tm.assert_series_equal(result, expected)
817+
818+
@pytest.mark.parametrize('tz', [None, 'UTC'])
819+
def test_mean_excludeds_datetimes(self, tz):
820+
# https://github.com/pandas-dev/pandas/issues/24752
821+
# Our long-term desired behavior is unclear, but the behavior in
822+
# 0.24.0rc1 was buggy.
823+
df = pd.DataFrame({"A": [pd.Timestamp('2000', tz=tz)] * 2})
824+
result = df.mean()
825+
expected = pd.Series()
826+
tm.assert_series_equal(result, expected)
827+
809828
# TODO: Ensure warning isn't emitted in the first place
810829
@pytest.mark.filterwarnings("ignore:All-NaN:RuntimeWarning")
811830
def test_median(self, 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)