Skip to content

Commit 88b71d2

Browse files
committed
REGR: bug in moments when using bottleneck
closes #16116
1 parent 008e9ec commit 88b71d2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pandas/core/nanops.py

+1
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):

pandas/tests/frame/test_analytics.py

+16
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,22 @@ 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']:
601+
result = getattr(df, op)()
602+
assert len(result) == 2
603+
604+
if nanops._USE_BOTTLENECK:
605+
nanops._USE_BOTTLENECK = False
606+
result = getattr(df, op)()
607+
assert len(result) == 2
608+
nanops._USE_BOTTLENECK = True
609+
594610
def test_cumsum(self):
595611
self.tsframe.loc[5:10, 0] = nan
596612
self.tsframe.loc[10:15, 1] = nan

0 commit comments

Comments
 (0)