diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index c94429b469641..184733da787af 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -632,3 +632,5 @@ Bug Fixes - Bug in ``pd.melt()`` where passing a tuple value for ``value_vars`` caused a ``TypeError`` (:issue:`15348`) - Bug in ``.eval()`` which caused multiline evals to fail with local variables not on the first line (:issue:`15342`) - Bug in ``pd.read_msgpack`` which did not allow to load dataframe with an index of type ``CategoricalIndex`` (:issue:`15487`) + +- Bug in ``nanops.py`` due to bottleneck, which produces overflow in nansum on Windows (:issue:`15453`) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 0cc3a2d039b5e..151cbd0dd6032 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -128,8 +128,7 @@ def _bn_ok_dtype(dt, name): # bottleneck does not properly upcast during the sum # so can overflow if name == 'nansum': - if dt.itemsize < 8: - return False + return False return True return False diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index 937c20d009b6b..f1c64ca96a80c 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -327,6 +327,12 @@ def test_nansum(self): self.check_funs(nanops.nansum, np.sum, allow_str=False, allow_date=False, allow_tdelta=True, check_dtype=False) + def test_nansum_overflow(self): + s = Series([2**31]) + self.assertEqual(s.sum(), 2147483648) + s = Series([2**31 - 1, 1]) + self.assertEqual(s.sum(), 2147483648) + def test_nanmean(self): self.check_funs(nanops.nanmean, np.mean, allow_complex=False, allow_obj=False, allow_str=False, allow_date=False,