[Numpy-discussion] lexsort() of datetime objects doesn't work

Charles R Harris charlesr.harris@gmail....
Thu Aug 19 19:03:29 CDT 2010


2010/8/19 Ernest Adrogué <eadrogue@gmx.net>

> Hi,
>
> I was trying to use lexsort with an array of
> datetime.date objects, but it doesn't seem to work.
>
> In [86]: date = np.array([datetime.date(2000, 9, 17),
>  datetime.date(2000, 10, 1),
>  datetime.date(2000, 10, 22),
>  datetime.date(2000, 11, 1)])
>
> In [90]: date
> Out[90]: array([2000-09-17, 2000-10-01, 2000-10-22, 2000-11-01],
> dtype=object)
>
> In [91]: np.lexsort((date,))
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
>
> /home/ernest/src/footy/dataset.py in <module>()
> ----> 1
>      2
>      3
>      4
>      5
>
> TypeError: merge sort not available for item 0
>
> The normal argsort works, however this is in a method that uses
> lexsort and I can't change it without breaking things.
>
>
The normal argsort calls the clib quicksort with a comparison function
whereas the mergesort needs to be implemented for the datetime data type. It
shouldn't be difficult to do, but it isn't done. I think datetime is
basically int64, so it should be possible to hook things up to call that
sorting routine.

Please open a ticket for this, it should be fixed.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100819/c86e5b1a/attachment.html 


More information about the NumPy-Discussion mailing list