Skip to content

Commit

Permalink
REF: separate out ShallowMixin (pandas-dev#29427)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Nov 6, 2019
1 parent c918f7e commit 77816ea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
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

0 comments on commit 77816ea

Please sign in to comment.