Skip to content

Commit 77816ea

Browse files
jbrockmendeljreback
authored andcommitted
REF: separate out ShallowMixin (#29427)
1 parent c918f7e commit 77816ea

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

pandas/core/base.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import builtins
55
from collections import OrderedDict
66
import textwrap
7-
from typing import Dict, FrozenSet, Optional
7+
from typing import Dict, FrozenSet, List, Optional
88
import warnings
99

1010
import numpy as np
@@ -569,7 +569,7 @@ def _aggregate_multiple_funcs(self, arg, _level, _axis):
569569
try:
570570
new_res = colg.aggregate(a)
571571

572-
except (TypeError, DataError):
572+
except TypeError:
573573
pass
574574
else:
575575
results.append(new_res)
@@ -618,6 +618,23 @@ def _aggregate_multiple_funcs(self, arg, _level, _axis):
618618
raise ValueError("cannot combine transform and aggregation operations")
619619
return result
620620

621+
def _get_cython_func(self, arg: str) -> Optional[str]:
622+
"""
623+
if we define an internal function for this argument, return it
624+
"""
625+
return self._cython_table.get(arg)
626+
627+
def _is_builtin_func(self, arg):
628+
"""
629+
if we define an builtin function for this argument, return it,
630+
otherwise return the arg
631+
"""
632+
return self._builtin_table.get(arg, arg)
633+
634+
635+
class ShallowMixin:
636+
_attributes = [] # type: List[str]
637+
621638
def _shallow_copy(self, obj=None, obj_type=None, **kwargs):
622639
"""
623640
return a new object with the replacement attributes
@@ -633,19 +650,6 @@ def _shallow_copy(self, obj=None, obj_type=None, **kwargs):
633650
kwargs[attr] = getattr(self, attr)
634651
return obj_type(obj, **kwargs)
635652

636-
def _get_cython_func(self, arg: str) -> Optional[str]:
637-
"""
638-
if we define an internal function for this argument, return it
639-
"""
640-
return self._cython_table.get(arg)
641-
642-
def _is_builtin_func(self, arg):
643-
"""
644-
if we define an builtin function for this argument, return it,
645-
otherwise return the arg
646-
"""
647-
return self._builtin_table.get(arg, arg)
648-
649653

650654
class IndexOpsMixin:
651655
"""

pandas/core/resample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
1818

1919
import pandas.core.algorithms as algos
20-
from pandas.core.base import DataError
20+
from pandas.core.base import DataError, ShallowMixin
2121
from pandas.core.generic import _shared_docs
2222
from pandas.core.groupby.base import GroupByMixin
2323
from pandas.core.groupby.generic import SeriesGroupBy
@@ -34,7 +34,7 @@
3434
_shared_docs_kwargs = dict() # type: Dict[str, str]
3535

3636

37-
class Resampler(_GroupBy):
37+
class Resampler(_GroupBy, ShallowMixin):
3838
"""
3939
Class for resampling datetimelike data, a groupby-like operation.
4040
See aggregate, transform, and apply functions on this object.

pandas/core/window/rolling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636

3737
from pandas._typing import Axis, FrameOrSeries, Scalar
38-
from pandas.core.base import DataError, PandasObject, SelectionMixin
38+
from pandas.core.base import DataError, PandasObject, SelectionMixin, ShallowMixin
3939
import pandas.core.common as com
4040
from pandas.core.index import Index, ensure_index
4141
from pandas.core.window.common import (
@@ -50,7 +50,7 @@
5050
)
5151

5252

53-
class _Window(PandasObject, SelectionMixin):
53+
class _Window(PandasObject, ShallowMixin, SelectionMixin):
5454
_attributes = [
5555
"window",
5656
"min_periods",

0 commit comments

Comments
 (0)