Skip to content

Commit 6ad32d2

Browse files
jrebackjorisvandenbossche
authored andcommitted
REGR: bug in moments when using bottleneck (#16124)
closes #16116
1 parent 4ca4fca commit 6ad32d2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pandas/core/nanops.py

+3
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def nanstd(values, axis=None, skipna=True, ddof=1):
381381
@bottleneck_switch(ddof=1)
382382
def nanvar(values, axis=None, skipna=True, ddof=1):
383383

384+
values = _values_from_object(values)
384385
dtype = values.dtype
385386
mask = isnull(values)
386387
if is_any_int_dtype(values):
@@ -489,6 +490,7 @@ def nanskew(values, axis=None, skipna=True):
489490
490491
"""
491492

493+
values = _values_from_object(values)
492494
mask = isnull(values)
493495
if not is_float_dtype(values.dtype):
494496
values = values.astype('f8')
@@ -543,6 +545,7 @@ def nankurt(values, axis=None, skipna=True):
543545
central moment.
544546
545547
"""
548+
values = _values_from_object(values)
546549
mask = isnull(values)
547550
if not is_float_dtype(values.dtype):
548551
values = values.astype('f8')

pandas/tests/frame/test_analytics.py

+17
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,23 @@ def test_numeric_only_flag(self):
591591
pytest.raises(TypeError, lambda: getattr(df2, meth)(
592592
axis=1, numeric_only=False))
593593

594+
def test_mixed_ops(self):
595+
# GH 16116
596+
df = DataFrame({'int': [1, 2, 3, 4],
597+
'float': [1., 2., 3., 4.],
598+
'str': ['a', 'b', 'c', 'd']})
599+
600+
for op in ['mean', 'std', 'var', 'skew',
601+
'kurt', 'sem']:
602+
result = getattr(df, op)()
603+
assert len(result) == 2
604+
605+
if nanops._USE_BOTTLENECK:
606+
nanops._USE_BOTTLENECK = False
607+
result = getattr(df, op)()
608+
assert len(result) == 2
609+
nanops._USE_BOTTLENECK = True
610+
594611
def test_cumsum(self):
595612
self.tsframe.loc[5:10, 0] = nan
596613
self.tsframe.loc[10:15, 1] = nan

0 commit comments

Comments
 (0)