Skip to content

Commit fef1830

Browse files
authored
REF: move ShallowMixin to groupby.base (#36341)
1 parent 3007baf commit fef1830

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

pandas/core/base.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import builtins
66
import textwrap
7-
from typing import Any, Callable, Dict, FrozenSet, List, Optional, Union
7+
from typing import Any, Callable, Dict, FrozenSet, Optional, Union
88

99
import numpy as np
1010

@@ -577,21 +577,6 @@ def _is_builtin_func(self, arg):
577577
return self._builtin_table.get(arg, arg)
578578

579579

580-
class ShallowMixin:
581-
_attributes: List[str] = []
582-
583-
def _shallow_copy(self, obj, **kwargs):
584-
"""
585-
return a new object with the replacement attributes
586-
"""
587-
if isinstance(obj, self._constructor):
588-
obj = obj.obj
589-
for attr in self._attributes:
590-
if attr not in kwargs:
591-
kwargs[attr] = getattr(self, attr)
592-
return self._constructor(obj, **kwargs)
593-
594-
595580
class IndexOpsMixin:
596581
"""
597582
Common ops mixin to support a unified interface / docs for Series / Index

pandas/core/groupby/base.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@
1313
OutputKey = collections.namedtuple("OutputKey", ["label", "position"])
1414

1515

16-
class GroupByMixin(PandasObject):
16+
class ShallowMixin(PandasObject):
17+
_attributes: List[str] = []
18+
19+
def _shallow_copy(self, obj, **kwargs):
20+
"""
21+
return a new object with the replacement attributes
22+
"""
23+
if isinstance(obj, self._constructor):
24+
obj = obj.obj
25+
for attr in self._attributes:
26+
if attr not in kwargs:
27+
kwargs[attr] = getattr(self, attr)
28+
return self._constructor(obj, **kwargs)
29+
30+
31+
class GotItemMixin(PandasObject):
1732
"""
1833
Provide the groupby facilities to the mixed object.
1934
"""

pandas/core/resample.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
2323

2424
import pandas.core.algorithms as algos
25-
from pandas.core.base import DataError, ShallowMixin
25+
from pandas.core.base import DataError
2626
from pandas.core.generic import NDFrame, _shared_docs
27-
from pandas.core.groupby.base import GroupByMixin
27+
from pandas.core.groupby.base import GotItemMixin, ShallowMixin
2828
from pandas.core.groupby.generic import SeriesGroupBy
2929
from pandas.core.groupby.groupby import (
3030
BaseGroupBy,
@@ -954,7 +954,7 @@ def h(self, _method=method):
954954
setattr(Resampler, method, h)
955955

956956

957-
class _GroupByMixin(GroupByMixin):
957+
class _GroupByMixin(GotItemMixin):
958958
"""
959959
Provide the groupby facilities.
960960
"""

pandas/core/window/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
99

10-
from pandas.core.groupby.base import GroupByMixin
10+
from pandas.core.groupby.base import GotItemMixin
1111
from pandas.core.indexes.api import MultiIndex
1212
from pandas.core.shared_docs import _shared_docs
1313

@@ -43,7 +43,7 @@ def f(x):
4343
return outer
4444

4545

46-
class WindowGroupByMixin(GroupByMixin):
46+
class WindowGroupByMixin(GotItemMixin):
4747
"""
4848
Provide the groupby facilities.
4949
"""

pandas/core/window/rolling.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@
4646
)
4747
from pandas.core.dtypes.missing import notna
4848

49-
from pandas.core.base import DataError, PandasObject, SelectionMixin, ShallowMixin
49+
from pandas.core.base import DataError, SelectionMixin
5050
import pandas.core.common as com
5151
from pandas.core.construction import extract_array
52+
from pandas.core.groupby.base import ShallowMixin
5253
from pandas.core.indexes.api import Index, MultiIndex
5354
from pandas.core.util.numba_ import NUMBA_FUNC_CACHE, maybe_use_numba
5455
from pandas.core.window.common import (
@@ -146,7 +147,7 @@ def func(arg, window, min_periods=None):
146147
return func
147148

148149

149-
class _Window(PandasObject, ShallowMixin, SelectionMixin):
150+
class _Window(ShallowMixin, SelectionMixin):
150151
_attributes: List[str] = [
151152
"window",
152153
"min_periods",

0 commit comments

Comments
 (0)