diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 2c5263f447951..92387e63ed782 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -351,6 +351,7 @@ Numeric - Bug in :meth:`Series.any`, :meth:`Series.all`, :meth:`DataFrame.any`, and :meth:`DataFrame.all` had the default value of ``bool_only`` set to ``None`` instead of ``False``; this change should have no impact on users (:issue:`53258`) - Bug in :meth:`Series.corr` and :meth:`Series.cov` raising ``AttributeError`` for masked dtypes (:issue:`51422`) - Bug in :meth:`Series.median` and :meth:`DataFrame.median` with object-dtype values containing strings that can be converted to numbers (e.g. "2") returning incorrect numeric results; these now raise ``TypeError`` (:issue:`34671`) +- Bug in :meth:`Series.sum` converting dtype ``uint64`` to ``int64`` (:issue:`53401`) Conversion diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index b405447239a7a..1b8a62d1ee0fb 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -324,8 +324,10 @@ def _get_values( def _get_dtype_max(dtype: np.dtype) -> np.dtype: # return a platform independent precision dtype dtype_max = dtype - if dtype.kind in "biu": + if dtype.kind in "bi": dtype_max = np.dtype(np.int64) + elif dtype.kind == "u": + dtype_max = np.dtype(np.uint64) elif dtype.kind == "f": dtype_max = np.dtype(np.float64) return dtype_max diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 5fa341c9eb74a..b02f8a19c77cb 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -1110,6 +1110,13 @@ def test_idxminmax_with_inf(self): assert s.idxmax() == 0 np.isnan(s.idxmax(skipna=False)) + def test_sum_uint64(self): + # GH 53401 + s = Series([10000000000000000000], dtype="uint64") + result = s.sum() + expected = np.uint64(10000000000000000000) + tm.assert_almost_equal(result, expected) + class TestDatetime64SeriesReductions: # Note: the name TestDatetime64SeriesReductions indicates these tests