Skip to content

REF: separate out ShallowMixin #29427

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 5 commits into from
Nov 6, 2019
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
34 changes: 19 additions & 15 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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:
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -50,7 +50,7 @@
)


class _Window(PandasObject, SelectionMixin):
class _Window(PandasObject, ShallowMixin, SelectionMixin):
_attributes = [
"window",
"min_periods",
Expand Down