Skip to content

Conversation

@tirthasheshpatel
Copy link
Contributor

Fixes #15063
This work is a follow up of #12658.
As requested in #15063, add NaT sort support for timedelta64 datatypes also.

@tylerjereddy tylerjereddy added the component: numpy.datetime64 (and timedelta64) label Dec 7, 2019
Copy link
Contributor

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks sensible---relatively easy to review given similarity to #12658 I think. I added a comment about the tests, but could always be a follow-up refinement thing.


@pytest.mark.parametrize("size", [
3, 21, 217, 1000])
def test_timedelta64_nat_argsort_stability(self, size):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this test and the one below are effectively copy/paste with M8 -> m8 from the first PR, we could also consider parametrizing over those two dtypes to reduce duplication. Maybe I just get carried away with the parameters though :) It would take a little more work, so not sure on the tradeoff value for maintainability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Looks lot cleaner now. Thanks!

@charris charris changed the title [MRG] FIX: Add support to sort timedelta64 NaT to end of the array ENH: Add support to sort timedelta64 NaT to end of the array Dec 7, 2019
@charris
Copy link
Member

charris commented Dec 7, 2019

Needs a release note.

@seberg seberg added the 09 - Backport-Candidate PRs tagged should be backported label Dec 7, 2019
(np.array([[51, -220, 'NaT'],
[-17, 'NaT', -90]], dtype='m8[us]'),
np.array([[-220, 51, 'NaT'],
[-90, -17, 'NaT']], dtype='m8[us]')),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this only uses ints and NaT strings. You could use two paramterizations: One for the dtype (maybe without the unit) and one for the list. And then move the np.array call into the test itself. That way you have half the code with the same result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks! 👍

@mattip
Copy link
Member

mattip commented Dec 11, 2019

Should this get a 1.18 milestone or is the "backport candidate" enough to make sure it is included in the 1.18 release?

@charris charris added this to the 1.18.0 release milestone Dec 11, 2019
@charris
Copy link
Member

charris commented Dec 11, 2019

I use the Backport-Candidate tag together with the milestone it should be backported to. Everything released later than that is assumed to also need the backport.

@seberg seberg merged commit 578f4e7 into numpy:master Dec 11, 2019
@seberg
Copy link
Member

seberg commented Dec 11, 2019

Thanks, for jumping and fixing it quickly!

charris pushed a commit to charris/numpy that referenced this pull request Dec 15, 2019
…gh-15068)

This work is a follow up of numpygh-12658.
As requested in numpygh-15063, add NaT sort support for timedelta64 datatypes also.

Fixes numpygh-15063
@charris charris added 01 - Enhancement and removed 09 - Backport-Candidate PRs tagged should be backported labels Dec 15, 2019
@charris charris removed this from the 1.18.0 release milestone Dec 15, 2019
@tirthasheshpatel tirthasheshpatel deleted the patch-2 branch April 28, 2020 06:06
asmeurer added a commit to asmeurer/numpy that referenced this pull request Aug 3, 2021
In numpy#12658 and numpy#15068 the sort ordering for datetime and timedelta was changed
so that NaT sorts to the end, but the internal compare array function was not
updated.

Fixes numpy#19574.
asmeurer added a commit to asmeurer/numpy that referenced this pull request Aug 3, 2021
…edelta

In numpy#12658 and numpy#15068 the sort ordering for datetime and timedelta was changed
so that NaT sorts to the end, but the internal compare array function was not
updated.

Fixes numpy#19574.
scratchmex pushed a commit to scratchmex/numpy that referenced this pull request Aug 13, 2021
…edelta

In numpy#12658 and numpy#15068 the sort ordering for datetime and timedelta was changed
so that NaT sorts to the end, but the internal compare array function was not
updated.

Fixes numpy#19574.
charris pushed a commit to charris/numpy that referenced this pull request Oct 10, 2021
…edelta

In numpy#12658 and numpy#15068 the sort ordering for datetime and timedelta was changed
so that NaT sorts to the end, but the internal compare array function was not
updated.

Fixes numpy#19574.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: NaT not sorted to end for timedelta

5 participants