Skip to content

REF: move ShallowMixin to groupby.base #36341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -954,7 +954,7 @@ def h(self, _method=method):
setattr(Resampler, method, h)


class _GroupByMixin(GroupByMixin):
class _GroupByMixin(GotItemMixin):
"""
Provide the groupby facilities.
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/window/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -43,7 +43,7 @@ def f(x):
return outer


class WindowGroupByMixin(GroupByMixin):
class WindowGroupByMixin(GotItemMixin):
"""
Provide the groupby facilities.
"""
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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",
Expand Down