-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Implement IntegerArray.sum #33538
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
f8d8d25
85d66ab
a44ae16
aa7ee1a
5fdb586
1d8eb4d
32a6b4e
9ee8ab2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from pandas._libs import lib, missing as libmissing | ||
from pandas._typing import ArrayLike | ||
from pandas.compat import set_function_name | ||
from pandas.compat.numpy import function as nv | ||
from pandas.util._decorators import cache_readonly | ||
|
||
from pandas.core.dtypes.base import ExtensionDtype | ||
|
@@ -573,6 +574,24 @@ def _reduce(self, name: str, skipna: bool = True, **kwargs): | |
|
||
return result | ||
|
||
def sum( | ||
self, | ||
axis=None, | ||
dtype=None, | ||
out=None, | ||
keepdims=False, | ||
initial=None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove all those unnecessary keywords and put them in a **kwargs ? |
||
skipna=True, | ||
min_count=0, | ||
): | ||
nv.validate_sum( | ||
(), dict(dtype=dtype, out=out, keepdims=keepdims, initial=initial) | ||
) | ||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,26 @@ 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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"values, expected", [([1, 2, 3], 6), ([1, 2, 3, None], 6), ([None], 0)] | ||
) | ||
def test_integer_array_numpy_sum(values, expected): | ||
arr = pd.array(values, dtype="Int64") | ||
result = np.sum(arr) | ||
assert result == expected | ||
|
||
|
||
# TODO(jreback) - these need testing / are broken | ||
|
||
# shift | ||
|
Uh oh!
There was an error while loading. Please reload this page.