Skip to content

Commit 449d912

Browse files
committed
add np.nan* funcs to cython_table
1 parent 0b7a08b commit 449d912

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Diff for: doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ Numeric
478478
- Bug in :meth:`DataFrame.agg`, :meth:`DataFrame.transform` and :meth:`DataFrame.apply` where,
479479
when supplied with a list of functions and ``axis=1`` (e.g. ``df.apply(['sum', 'mean'], axis=1)``),
480480
a ``TypeError`` was wrongly raised. For all three methods such calculation are now done correctly. (:issue:`16679`).
481+
- :meth:`Series.agg` can now handle numpy NaN-aware methods like :func:`numpy.nansum` (:issue:`19629`)
481482
-
482483

483484
Strings

Diff for: pandas/core/base.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
from pandas.core import common as com, algorithms
2323
import pandas.core.nanops as nanops
2424
import pandas._libs.lib as lib
25-
from pandas.compat.numpy import function as nv
25+
from pandas.compat.numpy import (function as nv, _np_version_under1p10,
26+
_np_version_under1p12)
2627
from pandas.compat import PYPY
2728
from pandas.util._decorators import (Appender, cache_readonly,
2829
deprecate_kwarg, Substitution)
@@ -184,24 +185,39 @@ class SelectionMixin(object):
184185
builtins.max: np.max,
185186
builtins.min: np.min
186187
}
188+
187189
_cython_table = {
188190
builtins.sum: 'sum',
189191
builtins.max: 'max',
190192
builtins.min: 'min',
191193
np.all: 'all',
192194
np.any: 'any',
193195
np.sum: 'sum',
196+
np.nansum: 'sum',
194197
np.mean: 'mean',
198+
np.nanmean: 'mean',
195199
np.prod: 'prod',
196200
np.std: 'std',
201+
np.nanstd: 'std',
197202
np.var: 'var',
203+
np.nanvar: 'var',
198204
np.median: 'median',
205+
np.nanmedian: 'median',
199206
np.max: 'max',
207+
np.nanmax: 'max',
200208
np.min: 'min',
209+
np.nanmin: 'min',
201210
np.cumprod: 'cumprod',
202-
np.cumsum: 'cumsum'
211+
np.cumsum: 'cumsum',
203212
}
204213

214+
if not _np_version_under1p10:
215+
_cython_table[np.nanprod] = 'prod'
216+
217+
if not _np_version_under1p12:
218+
_cython_table[np.nancumprod] = 'cumprod'
219+
_cython_table[np.nancumsum] = 'cumsum'
220+
205221
@property
206222
def _selection_name(self):
207223
"""

0 commit comments

Comments
 (0)