Skip to content

TST: fix for bottleneck >= 1.0 nansum behavior, xref #9422 #10270

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 1 commit into from
Jun 4, 2015
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
8 changes: 4 additions & 4 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ensure_float, _ensure_float64,
_ensure_int64, _ensure_object,
is_float, is_integer, is_complex,
is_float_dtype, is_floating_dtype,
is_float_dtype,
is_complex_dtype, is_integer_dtype,
is_bool_dtype, is_object_dtype,
is_datetime64_dtype, is_timedelta64_dtype,
Expand Down Expand Up @@ -373,7 +373,7 @@ def nansem(values, axis=None, skipna=True, ddof=1):
var = nanvar(values, axis, skipna, ddof=ddof)

mask = isnull(values)
if not is_floating_dtype(values):
if not is_float_dtype(values.dtype):
values = values.astype('f8')
count, _ = _get_counts_nanvar(mask, axis, ddof)

Expand Down Expand Up @@ -467,7 +467,7 @@ def nanargmin(values, axis=None, skipna=True):
def nanskew(values, axis=None, skipna=True):

mask = isnull(values)
if not is_floating_dtype(values):
if not is_float_dtype(values.dtype):
values = values.astype('f8')

count = _get_counts(mask, axis)
Expand Down Expand Up @@ -502,7 +502,7 @@ def nanskew(values, axis=None, skipna=True):
def nankurt(values, axis=None, skipna=True):

mask = isnull(values)
if not is_floating_dtype(values):
if not is_float_dtype(values.dtype):
values = values.astype('f8')

count = _get_counts(mask, axis)
Expand Down
16 changes: 13 additions & 3 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2316,7 +2316,7 @@ def test_iteritems(self):
self.assertFalse(hasattr(self.series.iteritems(), 'reverse'))

def test_sum(self):
self._check_stat_op('sum', np.sum)
self._check_stat_op('sum', np.sum, check_allna=True)

def test_sum_inf(self):
import pandas.core.nanops as nanops
Expand Down Expand Up @@ -2629,7 +2629,7 @@ def test_npdiff(self):
r = np.diff(s)
assert_series_equal(Series([nan, 0, 0, 0, nan]), r)

def _check_stat_op(self, name, alternate, check_objects=False):
def _check_stat_op(self, name, alternate, check_objects=False, check_allna=False):
import pandas.core.nanops as nanops

def testit():
Expand All @@ -2653,7 +2653,17 @@ def testit():
assert_almost_equal(f(self.series), alternate(nona.values))

allna = self.series * nan
self.assertTrue(np.isnan(f(allna)))

if check_allna:
# xref 9422
# bottleneck >= 1.0 give 0.0 for an allna Series sum
try:
self.assertTrue(nanops._USE_BOTTLENECK)
import bottleneck as bn
self.assertTrue(bn.__version__ >= LooseVersion('1.0'))
self.assertEqual(f(allna),0.0)
except:
self.assertTrue(np.isnan(f(allna)))

# dtype=object with None, it works!
s = Series([1, 2, 3, None, 5])
Expand Down