Skip to content

REGR: bug in moments when using bottleneck #16124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def nanstd(values, axis=None, skipna=True, ddof=1):
@bottleneck_switch(ddof=1)
def nanvar(values, axis=None, skipna=True, ddof=1):

values = _values_from_object(values)
dtype = values.dtype
mask = isnull(values)
if is_any_int_dtype(values):
Expand Down Expand Up @@ -489,6 +490,7 @@ def nanskew(values, axis=None, skipna=True):

"""

values = _values_from_object(values)
mask = isnull(values)
if not is_float_dtype(values.dtype):
values = values.astype('f8')
Expand Down Expand Up @@ -543,6 +545,7 @@ def nankurt(values, axis=None, skipna=True):
central moment.

"""
values = _values_from_object(values)
mask = isnull(values)
if not is_float_dtype(values.dtype):
values = values.astype('f8')
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,23 @@ def test_numeric_only_flag(self):
pytest.raises(TypeError, lambda: getattr(df2, meth)(
axis=1, numeric_only=False))

def test_mixed_ops(self):
# GH 16116
df = DataFrame({'int': [1, 2, 3, 4],
'float': [1., 2., 3., 4.],
'str': ['a', 'b', 'c', 'd']})

for op in ['mean', 'std', 'var', 'skew',
'kurt', 'sem']:
result = getattr(df, op)()
assert len(result) == 2

if nanops._USE_BOTTLENECK:
nanops._USE_BOTTLENECK = False
result = getattr(df, op)()
assert len(result) == 2
nanops._USE_BOTTLENECK = True

def test_cumsum(self):
self.tsframe.loc[5:10, 0] = nan
self.tsframe.loc[10:15, 1] = nan
Expand Down