Skip to content
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ Other
- Bug in :meth:`Series.map` not raising on invalid ``na_action`` (:issue:`32815`)
- Bug in :meth:`DataFrame.__dir__` caused a segfault when using unicode surrogates in a column name (:issue:`25509`)
- Bug in :meth:`DataFrame.plot.scatter` caused an error when plotting variable marker sizes (:issue:`32904`)
- :class:`IntegerArray` now implements the ``sum`` operation

.. ---------------------------------------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,12 @@ def _reduce(self, name: str, skipna: bool = True, **kwargs):

return result

def sum(self, skipna: bool = True, min_count: int = 0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should make the signature match PandasArray.sum etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, and we still want to keep axis (even though it wouldn't be used here)?

result = masked_reductions.sum(
values=self._data, mask=self._mask, skipna=skipna, min_count=min_count
)
return result

def _maybe_mask_result(self, result, mask, other, op_name: str):
"""
Parameters
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/arrays/integer/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def test_value_counts_empty():
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("min_count", [0, 4])
def test_integer_array_sum(skipna, min_count):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is e.g. Series[Int64].sum() or DataFrame[Int64].sum() fixed by this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are actually already working, just not for IntegerArray specifically

arr = pd.array([1, 2, 3, None], dtype="Int64")
result = arr.sum(skipna=skipna, min_count=min_count)
if skipna and min_count == 0:
assert result == 6
else:
assert result is pd.NA


# TODO(jreback) - these need testing / are broken

# shift
Expand Down