Skip to content

NaT and extended sort order #12629

@TomAugspurger

Description

@TomAugspurger

https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.sort.html#numpy.sort describes how np.nan is handled for floating point data. NaT and datetime data are not mentioned.

Reproducing code example:

In the following, NaN is sorted to the end, while NaT is sorted to the start.

In [32]: arr = np.array([np.nan, 1, 2, 3])

In [33]: arr.sort(); arr
Out[33]: array([ 1.,  2.,  3., nan])

In [34]: dtarr = np.array(['NaT', 1, 2, 3], dtype='datetime64[ns]')

In [35]: dtarr.sort(); dtarr
Out[35]:
array([                          'NaT', '1970-01-01T00:00:00.000000001',
       '1970-01-01T00:00:00.000000002', '1970-01-01T00:00:00.000000003'],
      dtype='datetime64[ns]')

So my question: is NaT sorting to the start a bug or deliberate? If it's deliberate, I could add a section to the docs noting that.

Numpy/Python version information:

1.16.0.dev0+9cc9f01 3.7.1 (default, Nov 6 2018, 18:45:35)
[Clang 10.0.0 (clang-1000.11.45.5)]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions