-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Implement _most_ of the EA interface for DTA/TDA #23643
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
Changes from 6 commits
52e4d6b
c2bcd80
0ce0a7c
45c8161
75f6944
0fb5029
1a781ab
ccbffe4
eceebc7
a6065cc
3cb072e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ | |
from pandas.core.dtypes.missing import isna | ||
|
||
import pandas.core.common as com | ||
from pandas.core.algorithms import checked_add_with_arr | ||
from pandas.core.algorithms import checked_add_with_arr, take, unique1d | ||
|
||
from .base import ExtensionOpsMixin | ||
from pandas.util._decorators import deprecate_kwarg | ||
|
@@ -196,6 +196,71 @@ def astype(self, dtype, copy=True): | |
return self._box_values(self.asi8) | ||
return super(DatetimeLikeArrayMixin, self).astype(dtype, copy) | ||
|
||
# ------------------------------------------------------------------ | ||
# ExtensionArray Interface | ||
# TODO: | ||
# * _from_sequence | ||
# * argsort / _values_for_argsort | ||
# * _reduce | ||
|
||
def unique(self): | ||
result = unique1d(self.asi8) | ||
return type(self)(result, dtype=self.dtype) | ||
|
||
def _validate_fill_value(self, fill_value): | ||
""" | ||
If a fill_value is passed to `take` convert it to an i8 representation, | ||
raising ValueError if this is not possible. | ||
|
||
Parameters | ||
---------- | ||
fill_value : object | ||
|
||
Returns | ||
------- | ||
fill_value : np.int64 | ||
|
||
Raises | ||
------ | ||
ValueError | ||
""" | ||
raise AbstractMethodError(self) | ||
|
||
def take(self, indices, allow_fill=False, fill_value=None): | ||
if allow_fill: | ||
fill_value = self._validate_fill_value(fill_value) | ||
|
||
new_values = take(self.asi8, | ||
indices, | ||
allow_fill=allow_fill, | ||
fill_value=fill_value) | ||
|
||
return type(self)(new_values, dtype=self.dtype) | ||
|
||
@classmethod | ||
def _concat_same_type(cls, to_concat): | ||
# for TimedeltaArray and PeriodArray; DatetimeArray overrides | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem being that DatetimeArray needs to pass through For PeriodArray at least (haven't checked TimedeltaArray) you should able to implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As opposed to PeriodArray, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, the PeriodArray constructor allows duplicate PeriodArray(data, freq='H', dtype=PeriodDtype("H") should be fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yah, we added dtype to the PeriodArray constructor specifically so that type(self)(values, freq=self.freq, dtype=self.dtype) would be valid for all three TDA/DTA/PA classes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, that's not what I was meaning. The difference is the meaning of |
||
freqs = {x.freq for x in to_concat} | ||
assert len(freqs) == 1 | ||
freq = list(freqs)[0] | ||
values = np.concatenate([x.asi8 for x in to_concat]) | ||
return cls._simple_new(values, freq=freq) | ||
|
||
def copy(self, deep=False): | ||
values = self.asi8 | ||
if deep: | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
values = values.copy() | ||
return type(self)(values, dtype=self.dtype, freq=self.freq) | ||
|
||
def _values_for_factorize(self): | ||
return self.asi8, iNaT | ||
|
||
@classmethod | ||
def _from_factorized(cls, values, original): | ||
if is_datetime64tz_dtype(original): | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return cls(values, tz=original.tz, freq=original.freq) | ||
return cls(values, freq=original.freq) | ||
|
||
# ------------------------------------------------------------------ | ||
# Null Handling | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.