A Friday 11 July 2008, Pierre GM escrigué: > On Friday 11 July 2008 14:01:39 Francesc Alted wrote: > > Ah! Very smart! I wonder if we could use this to implement a > > special array with a fixed timestep that could be indexed by time > > instead than by index. Something like: > > > > t1 = datetime.datetime(1,2,3) > > t2 = datetime.datetime(3,4,5) > > Well, we coded something like that in our TimeSeries class: its > __getitem__ is quite bloated, but you can use integers/dates/strings > as indices and get your result. We implemented in Python, so that's > slow, but it works great.
That's nice! But it would be even nicer if that could be integrated in general NumPy arrays after the introduction of the datetime types (just thinking aloud ;-) > About the representation (datetime vs integer): I think that > everything depends on what you want to do. Our DateArray class > pretty-prints results in a human format while still using integers > internally. For example, > > >>> import scikits.timeseries as ts > >>> example=ts.date_array(start_date=ts.now('M'), length=6) > >>> print example > > [Jul-2008 Aug-2008 Sep-2008 Oct-2008 Nov-2008 Dec-2008] That's ok. But my point is that this forces you to represent absolute dates, and that's what I was trying to avoid. The proposed date/time types could work either as absolute or relative, depending on the needs of the user. Only when converting them to the Python ``datetime.datetime`` containers a time origin will be set, and hence, they represents an absolute date then. However, if you convert the NumPy datetimes into a ``datetime.timedelta``, your times will continue to be relative. That would be utterly important so as not to clutter NumPy too much with another set of 'timedelta' types, IMO. > > >>> print example.tovalue() > > [24091 24092 24093 24094 24095 24096] > > >>> print example.tolist() > > [datetime.datetime(2008, 7, 31, 0, 0), datetime.datetime(2008, 8, 31, > 0, 0), datetime.datetime(2008, 9, 30, 0, 0), datetime.datetime(2008, > 10, 31, 0, 0), datetime.datetime(2008, 11, 30, 0, 0), > datetime.datetime(2008, 12, 31, 0, 0)] Yes. With our proposal, '.tolist()' would return the same representation than yours. > Et voila (like we say at home) And at many other parts of the planet too ;-) > > Francesc: > A few weeks back, I coded some interface between TimeSeries and > pytables. I haven't really cleaned it yet but will post it very soon. > Roughly, a TimeSeries object is the combination of a MaskedArray and > a DateArray, and it can be readily transformed into a record-array > which in turns can be transformed into a table. > I experimented with various levels of nesting in the definition of > dtypes, and I've been amazed by how powerful tailor-made dtypes can > be. I bow to Travis O. et al. for the implementation... I completely agree. Travis made a stunning work with the implementation of the nested dtypes (as many other things in NumPy, but I perhaps appreciate this the most). Cheers, -- Francesc Alted _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion