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

Ernest Adrogué eadrogue at gmx.net
Fri Aug 20 08:40:46 EDT 2010


19/08/10 @ 18:03 (-0600), thus spake Charles R Harris:
> 2010/8/19 Ernest Adrogué <eadrogue at 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.

Thank you. Ticket opened here:
http://projects.scipy.org/scipy/ticket/1268

Cheers,

Ernest



More information about the NumPy-Discussion mailing list