Skip to content

Commit 4dc9980

Browse files
committed
add np.nan* funcs to cython_table
1 parent da9d851 commit 4dc9980

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ Numeric
10801080
- Bug in :meth:`DataFrame.astype` to extension dtype may raise ``AttributeError`` (:issue:`22578`)
10811081
- Bug in :class:`DataFrame` with ``timedelta64[ns]`` dtype arithmetic operations with ``ndarray`` with integer dtype incorrectly treating the narray as ``timedelta64[ns]`` dtype (:issue:`23114`)
10821082
- Bug in :meth:`Series.rpow` with object dtype ``NaN`` for ``1 ** NA`` instead of ``1`` (:issue:`22922`).
1083+
- :meth:`Series.agg` can now handle numpy NaN-aware methods like :func:`numpy.nansum` (:issue:`19629`)
10831084

10841085
Strings
10851086
^^^^^^^

pandas/core/base.py

+12
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,39 @@ class SelectionMixin(object):
178178
_selection = None
179179
_internal_names = ['_cache', '__setstate__']
180180
_internal_names_set = set(_internal_names)
181+
181182
_builtin_table = OrderedDict((
182183
(builtins.sum, np.sum),
183184
(builtins.max, np.max),
184185
(builtins.min, np.min),
185186
))
187+
186188
_cython_table = OrderedDict((
187189
(builtins.sum, 'sum'),
188190
(builtins.max, 'max'),
189191
(builtins.min, 'min'),
190192
(np.all, 'all'),
191193
(np.any, 'any'),
192194
(np.sum, 'sum'),
195+
(np.nansum, 'sum'),
193196
(np.mean, 'mean'),
197+
(np.nanmean, 'mean'),
194198
(np.prod, 'prod'),
199+
(np.nanprod, 'prod'),
195200
(np.std, 'std'),
201+
(np.nanstd, 'std'),
196202
(np.var, 'var'),
203+
(np.nanvar, 'var'),
197204
(np.median, 'median'),
205+
(np.nanmedian, 'median'),
198206
(np.max, 'max'),
207+
(np.nanmax, 'max'),
199208
(np.min, 'min'),
209+
(np.nanmin, 'min'),
200210
(np.cumprod, 'cumprod'),
211+
(np.nancumprod, 'cumprod'),
201212
(np.cumsum, 'cumsum'),
213+
(np.nancumsum, 'cumsum'),
202214
))
203215

204216
@property

pandas/tests/groupby/aggregate/test_other.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -487,17 +487,7 @@ def test_agg_structs_series(structure, expected):
487487
tm.assert_series_equal(result, expected)
488488

489489

490-
@pytest.mark.parametrize('observed', [
491-
True,
492-
pytest.param(False,
493-
marks=pytest.mark.xfail(reason="GH#18869: agg func not "
494-
"called on empty groups.",
495-
strict=True)),
496-
pytest.param(None,
497-
marks=pytest.mark.xfail(reason="GH#18869: agg func not "
498-
"called on empty groups.",
499-
strict=True))
500-
])
490+
@pytest.mark.parametrize('observed', [True, False, None])
501491
def test_agg_category_nansum(observed):
502492
categories = ['a', 'b', 'c']
503493
df = pd.DataFrame({"A": pd.Categorical(['a', 'a', 'b'],

0 commit comments

Comments
 (0)