Skip to content

CLN: remove DatetimelikeDelegateMixin #31480

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
Jan 31, 2020
Merged
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
43 changes: 1 addition & 42 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
Base and utility classes for tseries type pandas objects.
"""
import operator
from typing import Any, List, Optional, Set, Union
from typing import Any, List, Optional, Union

import numpy as np

Expand Down Expand Up @@ -30,7 +29,6 @@
from pandas.core.dtypes.missing import is_valid_nat_for_dtype, isna

from pandas.core import algorithms
from pandas.core.accessor import PandasDelegate
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
from pandas.core.base import _shared_docs
Expand Down Expand Up @@ -932,42 +930,3 @@ def insert(self, loc, item):
raise TypeError(
f"cannot insert {type(self).__name__} with incompatible label"
)


class DatetimelikeDelegateMixin(PandasDelegate):
"""
Delegation mechanism, specific for Datetime, Timedelta, and Period types.

Functionality is delegated from the Index class to an Array class. A
few things can be customized

* _delegated_methods, delegated_properties : List
The list of property / method names being delagated.
* raw_methods : Set
The set of methods whose results should should *not* be
boxed in an index, after being returned from the array
* raw_properties : Set
The set of properties whose results should should *not* be
boxed in an index, after being returned from the array
"""

# raw_methods : dispatch methods that shouldn't be boxed in an Index
_raw_methods: Set[str] = set()
# raw_properties : dispatch properties that shouldn't be boxed in an Index
_raw_properties: Set[str] = set()
_data: Union[DatetimeArray, TimedeltaArray, PeriodArray]

def _delegate_property_get(self, name, *args, **kwargs):
result = getattr(self._data, name)
if name not in self._raw_properties:
result = Index(result, name=self.name)
return result

def _delegate_property_set(self, name: str, value, *args, **kwargs):
setattr(self._data, name, value)

def _delegate_method(self, name, *args, **kwargs):
result = operator.methodcaller(name, *args, **kwargs)(self._data)
if name not in self._raw_methods:
result = Index(result, name=self.name)
return result