[Numpy-discussion] RFC: A proposal for implementing some date/time types in NumPy

Pierre GM pgmdevlist@gmail....
Fri Jul 11 13:20:26 CDT 2008


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.

On Friday 11 July 2008 13:54:31 Jon Wright wrote:
> Hello,
>
> Nice idea - please can you make it work with matplotlib's time/date
> stuff too?

<product placement>
FYI, the scikits.timeseries has a module for plotting w/ TimeSeries objects. 
We had fun implementing the part where the labels change depending on the 
level of zoom...
</product placement>

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]
>>> 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)]

Et voila (like we say at home)

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...



More information about the Numpy-discussion mailing list