-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
COMPAT: Argsort position matches NumPy #31210
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 1 commit
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 |
---|---|---|
|
@@ -180,6 +180,9 @@ def map(self, mapper, na_action=None): | |
except Exception: | ||
return self.astype(object).map(mapper) | ||
|
||
def argsort(self, *args, **kwargs) -> np.ndarray: | ||
return np.argsort(self._data) | ||
|
||
def sort_values(self, return_indexer=False, ascending=True): | ||
""" | ||
Return sorted copy of Index. | ||
|
@@ -191,10 +194,7 @@ def sort_values(self, return_indexer=False, ascending=True): | |
sorted_index = self.take(_as) | ||
return sorted_index, _as | ||
else: | ||
# NB: using asi8 instead of _ndarray_values matters in numpy 1.18 | ||
# because the treatment of NaT has been changed to put NaT last | ||
# instead of first. | ||
sorted_values = np.sort(self.asi8) | ||
sorted_values = np.sort(self._ndarray_values) | ||
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. this means i8n for PeriodIndex (so NaT to the front), m8 for TimedeltaIndex (so NaT to the front until numpy updates td64 to match dt64) and M8 for DatetimeIndex, (so NaT to the end). Is that what you're going for here? 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. NumPy has fixed the timedelta sorting, at least for 1.19+ In [22]: arr = np.array([np.timedelta64(2, 'ns'), np.timedelta64('NaT', 'ns'), np.timedelta64(1, 'ns')])
In [23]: arr.sort()
In [24]: arr
Out[24]: array([ 1, 2, 'NaT'], dtype='timedelta64[ns]') |
||
|
||
freq = self.freq | ||
if freq is not None and not is_period_dtype(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think if we want this to be consistent across DTI/TDI/PI this needs to take a
.view("M8[ns]")
Also should this happen at the DTA/TDA/PA level and get passed through?