Skip to content

WIP: DatetimeArray+TimedeltaArray #23415

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

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
implement unique
  • Loading branch information
jbrockmendel committed Nov 2, 2018
commit 47689bea930cc5665ccc554f9b9ccdeff902680c
1 change: 1 addition & 0 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def ceil(self, freq, ambiguous='raise'):

class DatetimeIndexOpsMixin(DatetimeLikeArrayMixin):
""" common ops mixin to support a unified interface datetimelike Index """
copy = Index.copy

# DatetimeLikeArrayMixin assumes subclasses are mutable, so these are
# properties there. They can be made into cache_readonly for Index
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,10 @@ def unique(self, level=None):
naive = type(self)(self._ndarray_values, copy=False)
else:
naive = self
result = super(DatetimeIndex, naive).unique(level=level)

if level is not None:
self._validate_index_level(level)
result = DatetimeArray.unique(self)
return self._shallow_copy(result.values)

def union(self, other):
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,12 @@ def delete(self, loc):

return TimedeltaIndex(new_tds, name=self.name, freq=freq)

def unique(self, level=None):
if level is not None:
self._validate_index_level(level)
result = TimedeltaArrayMixin.unique(self)
return self._shallow_copy(result.values)


TimedeltaIndex._add_comparison_ops()
TimedeltaIndex._add_numeric_methods()
Expand Down