diff --git a/pandas/core/base.py b/pandas/core/base.py index 1a2f906f97152..65e531f96614a 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -4,7 +4,7 @@ import builtins from collections import OrderedDict import textwrap -from typing import Dict, FrozenSet, Optional +from typing import Dict, FrozenSet, List, Optional import warnings import numpy as np @@ -569,7 +569,7 @@ def _aggregate_multiple_funcs(self, arg, _level, _axis): try: new_res = colg.aggregate(a) - except (TypeError, DataError): + except TypeError: pass else: results.append(new_res) @@ -618,6 +618,23 @@ def _aggregate_multiple_funcs(self, arg, _level, _axis): raise ValueError("cannot combine transform and aggregation operations") return result + def _get_cython_func(self, arg: str) -> Optional[str]: + """ + if we define an internal function for this argument, return it + """ + return self._cython_table.get(arg) + + def _is_builtin_func(self, arg): + """ + if we define an builtin function for this argument, return it, + otherwise return the arg + """ + return self._builtin_table.get(arg, arg) + + +class ShallowMixin: + _attributes = [] # type: List[str] + def _shallow_copy(self, obj=None, obj_type=None, **kwargs): """ return a new object with the replacement attributes @@ -633,19 +650,6 @@ def _shallow_copy(self, obj=None, obj_type=None, **kwargs): kwargs[attr] = getattr(self, attr) return obj_type(obj, **kwargs) - def _get_cython_func(self, arg: str) -> Optional[str]: - """ - if we define an internal function for this argument, return it - """ - return self._cython_table.get(arg) - - def _is_builtin_func(self, arg): - """ - if we define an builtin function for this argument, return it, - otherwise return the arg - """ - return self._builtin_table.get(arg, arg) - class IndexOpsMixin: """ diff --git a/pandas/core/resample.py b/pandas/core/resample.py index e68a2efc3f4e6..9d7ddcf3c7727 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -17,7 +17,7 @@ from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries import pandas.core.algorithms as algos -from pandas.core.base import DataError +from pandas.core.base import DataError, ShallowMixin from pandas.core.generic import _shared_docs from pandas.core.groupby.base import GroupByMixin from pandas.core.groupby.generic import SeriesGroupBy @@ -34,7 +34,7 @@ _shared_docs_kwargs = dict() # type: Dict[str, str] -class Resampler(_GroupBy): +class Resampler(_GroupBy, ShallowMixin): """ Class for resampling datetimelike data, a groupby-like operation. See aggregate, transform, and apply functions on this object. diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 68eb1f630bfc3..0718acd6360bf 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -35,7 +35,7 @@ ) from pandas._typing import Axis, FrameOrSeries, Scalar -from pandas.core.base import DataError, PandasObject, SelectionMixin +from pandas.core.base import DataError, PandasObject, SelectionMixin, ShallowMixin import pandas.core.common as com from pandas.core.index import Index, ensure_index from pandas.core.window.common import ( @@ -50,7 +50,7 @@ ) -class _Window(PandasObject, SelectionMixin): +class _Window(PandasObject, ShallowMixin, SelectionMixin): _attributes = [ "window", "min_periods",