Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: series sum changes dtype uint64 to int64 #53418

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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down