Skip to content

Commit

Permalink
add np.nan* funcs to cython_table (pandas-dev#22109)
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 authored and Pingviinituutti committed Feb 28, 2019
1 parent 2e4f780 commit 9fb9137
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ Numeric
- Bug in :meth:`DataFrame.astype` to extension dtype may raise ``AttributeError`` (:issue:`22578`)
- 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`)
- Bug in :meth:`Series.rpow` with object dtype ``NaN`` for ``1 ** NA`` instead of ``1`` (:issue:`22922`).
- :meth:`Series.agg` can now handle numpy NaN-aware methods like :func:`numpy.nansum` (:issue:`19629`)

Strings
^^^^^^^
Expand Down
12 changes: 12 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,39 @@ class SelectionMixin(object):
_selection = None
_internal_names = ['_cache', '__setstate__']
_internal_names_set = set(_internal_names)

_builtin_table = OrderedDict((
(builtins.sum, np.sum),
(builtins.max, np.max),
(builtins.min, np.min),
))

_cython_table = OrderedDict((
(builtins.sum, 'sum'),
(builtins.max, 'max'),
(builtins.min, 'min'),
(np.all, 'all'),
(np.any, 'any'),
(np.sum, 'sum'),
(np.nansum, 'sum'),
(np.mean, 'mean'),
(np.nanmean, 'mean'),
(np.prod, 'prod'),
(np.nanprod, 'prod'),
(np.std, 'std'),
(np.nanstd, 'std'),
(np.var, 'var'),
(np.nanvar, 'var'),
(np.median, 'median'),
(np.nanmedian, 'median'),
(np.max, 'max'),
(np.nanmax, 'max'),
(np.min, 'min'),
(np.nanmin, 'min'),
(np.cumprod, 'cumprod'),
(np.nancumprod, 'cumprod'),
(np.cumsum, 'cumsum'),
(np.nancumsum, 'cumsum'),
))

@property
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/groupby/aggregate/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,6 @@ def test_agg_structs_series(structure, expected):
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize('observed', [
True,
pytest.param(False,
marks=pytest.mark.xfail(reason="GH#18869: agg func not "
"called on empty groups.",
strict=True)),
pytest.param(None,
marks=pytest.mark.xfail(reason="GH#18869: agg func not "
"called on empty groups.",
strict=True))
])
def test_agg_category_nansum(observed):
categories = ['a', 'b', 'c']
df = pd.DataFrame({"A": pd.Categorical(['a', 'a', 'b'],
Expand Down

0 comments on commit 9fb9137

Please sign in to comment.