Skip to content

Commit

Permalink
Merge pull request #10270 from jreback/fix
Browse files Browse the repository at this point in the history
TST: fix for bottleneck >= 1.0 nansum behavior, xref #9422
  • Loading branch information
jreback committed Jun 4, 2015
2 parents efc4a08 + e9f83ce commit 7516ec7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
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

0 comments on commit 7516ec7

Please sign in to comment.