diff --git a/pandas/core/base.py b/pandas/core/base.py index 53378c0e0e252..4d5cddc086b2a 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -4,7 +4,7 @@ import builtins import textwrap -from typing import Any, Callable, Dict, FrozenSet, List, Optional, Union +from typing import Any, Callable, Dict, FrozenSet, Optional, Union import numpy as np @@ -577,21 +577,6 @@ def _is_builtin_func(self, arg): return self._builtin_table.get(arg, arg) -class ShallowMixin: - _attributes: List[str] = [] - - def _shallow_copy(self, obj, **kwargs): - """ - return a new object with the replacement attributes - """ - if isinstance(obj, self._constructor): - obj = obj.obj - for attr in self._attributes: - if attr not in kwargs: - kwargs[attr] = getattr(self, attr) - return self._constructor(obj, **kwargs) - - class IndexOpsMixin: """ Common ops mixin to support a unified interface / docs for Series / Index diff --git a/pandas/core/groupby/base.py b/pandas/core/groupby/base.py index 999873e7b81e4..9cfd13f95ca0e 100644 --- a/pandas/core/groupby/base.py +++ b/pandas/core/groupby/base.py @@ -13,7 +13,22 @@ OutputKey = collections.namedtuple("OutputKey", ["label", "position"]) -class GroupByMixin(PandasObject): +class ShallowMixin(PandasObject): + _attributes: List[str] = [] + + def _shallow_copy(self, obj, **kwargs): + """ + return a new object with the replacement attributes + """ + if isinstance(obj, self._constructor): + obj = obj.obj + for attr in self._attributes: + if attr not in kwargs: + kwargs[attr] = getattr(self, attr) + return self._constructor(obj, **kwargs) + + +class GotItemMixin(PandasObject): """ Provide the groupby facilities to the mixed object. """ diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 4ba253e76128e..29b7bd7a63faa 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -22,9 +22,9 @@ from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries import pandas.core.algorithms as algos -from pandas.core.base import DataError, ShallowMixin +from pandas.core.base import DataError from pandas.core.generic import NDFrame, _shared_docs -from pandas.core.groupby.base import GroupByMixin +from pandas.core.groupby.base import GotItemMixin, ShallowMixin from pandas.core.groupby.generic import SeriesGroupBy from pandas.core.groupby.groupby import ( BaseGroupBy, @@ -954,7 +954,7 @@ def h(self, _method=method): setattr(Resampler, method, h) -class _GroupByMixin(GroupByMixin): +class _GroupByMixin(GotItemMixin): """ Provide the groupby facilities. """ diff --git a/pandas/core/window/common.py b/pandas/core/window/common.py index df60d2dcf5e84..6452eb8c6b3a9 100644 --- a/pandas/core/window/common.py +++ b/pandas/core/window/common.py @@ -7,7 +7,7 @@ from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries -from pandas.core.groupby.base import GroupByMixin +from pandas.core.groupby.base import GotItemMixin from pandas.core.indexes.api import MultiIndex from pandas.core.shared_docs import _shared_docs @@ -43,7 +43,7 @@ def f(x): return outer -class WindowGroupByMixin(GroupByMixin): +class WindowGroupByMixin(GotItemMixin): """ Provide the groupby facilities. """ diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 648ab4d25be83..d094cc7d70a21 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -46,9 +46,10 @@ ) from pandas.core.dtypes.missing import notna -from pandas.core.base import DataError, PandasObject, SelectionMixin, ShallowMixin +from pandas.core.base import DataError, SelectionMixin import pandas.core.common as com from pandas.core.construction import extract_array +from pandas.core.groupby.base import ShallowMixin from pandas.core.indexes.api import Index, MultiIndex from pandas.core.util.numba_ import NUMBA_FUNC_CACHE, maybe_use_numba from pandas.core.window.common import ( @@ -146,7 +147,7 @@ def func(arg, window, min_periods=None): return func -class _Window(PandasObject, ShallowMixin, SelectionMixin): +class _Window(ShallowMixin, SelectionMixin): _attributes: List[str] = [ "window", "min_periods",