-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
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 7 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,74 @@ 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): | ||
freqs = {x.freq for x in to_concat} | ||
assert len(freqs) == 1 | ||
freq = list(freqs)[0] | ||
|
||
# dtype captures tz for datetime64tz case | ||
dtypes = {x.dtype for x in to_concat} | ||
assert len(dtypes) == 1 | ||
dtype = list(dtypes)[0] | ||
|
||
values = np.concatenate([x.asi8 for x in to_concat]) | ||
return cls(values, dtype=dtype, 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): | ||
return cls(values, dtype=original.dtype, freq=original.freq) | ||
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. Does it make sense to pass Although in practice, if you have a freq, that means you have a regular and unique array to start with, so the factorization is kind of a no-op and the result will still have the same freq? (but might be missing corner cases) 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. Thinking of a possible corner case, which is currently actually broken: a sorted factorize of a DatetimeIndex with a negative freq:
|
||
|
||
# ------------------------------------------------------------------ | ||
# Null Handling | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.