[SciPy-dev] Timeseries Unusual Behaviour
Dave
dave.hirschfeld at gmail.com
Tue Oct 14 13:52:02 EDT 2008
Firstly, thanks for a great package I find it very useful for my timeseries
analysis at work. I have however just stumbled upon some unusual behaviour...
It appears that the `date_array` function sorts the dates when constructing a
DateArray instance. This bit me when I tried to compare the timestamps against
another `values` array so perhaps this behaviour should be mentioned in the
docstring if it is indeed desirable.
The `time_series` function magically appears to be able to handle the sorted
`DateArray` when first called, but when called again with the same arguments it
gets the order wrong. Is this reproducible? Is it a bug? Or am I just doing
something stupid?!
Thanks,
Dave
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
IPython 0.9.1 -- An enhanced Interactive Python.
In [2]: import datetime
In [3]: import scikits.timeseries as ts
In [4]: ts.__version__
Out[4]: '0.67.dev'
In [5]: numpy.__version__
Out[5]: '1.3.0.dev5859'
In [6]: dates = (datetime.datetime(2011, 5, 1, 0, 0),
...: datetime.datetime(2011, 8, 1, 0, 0),
...: datetime.datetime(2011, 6, 1, 0, 0),
...: datetime.datetime(2011, 9, 1, 0, 0),
...: datetime.datetime(2011, 7, 1, 0, 0))
In [7]: values = rand(len(dates))
In [8]: zip(dates,values)
Out[8]:
[(datetime.datetime(2011, 5, 1, 0, 0), 0.68325143668413102),
(datetime.datetime(2011, 8, 1, 0, 0), 0.5341201248082369),
(datetime.datetime(2011, 6, 1, 0, 0), 0.419866941013046),
(datetime.datetime(2011, 9, 1, 0, 0), 0.73489099683479775),
(datetime.datetime(2011, 7, 1, 0, 0), 0.7040093508897648)]
In [9]: date_array = ts.date_array(dlist=dates)
In [10]: # INCORRECT !
In [11]: zip(date_array,values)
Out[11]:
[(<U : 01-May-2011>, 0.68325143668413102),
(<U : 01-Jun-2011>, 0.5341201248082369),
(<U : 01-Jul-2011>, 0.419866941013046),
(<U : 01-Aug-2011>, 0.73489099683479775),
(<U : 01-Sep-2011>, 0.7040093508897648)]
In [12]: # CORRECT
In [13]: timeseries = ts.time_series(values,dates=date_array)
In [14]: zip(timeseries.dates,timeseries.data)
Out[14]:
[(<U : 01-May-2011>, 0.68325143668413102),
(<U : 01-Jun-2011>, 0.419866941013046),
(<U : 01-Jul-2011>, 0.7040093508897648),
(<U : 01-Aug-2011>, 0.5341201248082369),
(<U : 01-Sep-2011>, 0.73489099683479775)]
In [15]: # INCORRECT !?!
In [16]: timeseries = ts.time_series(values,dates=date_array)
In [17]: zip(timeseries.dates,timeseries.data)
Out[17]:
[(<U : 01-May-2011>, 0.68325143668413102),
(<U : 01-Jun-2011>, 0.5341201248082369),
(<U : 01-Jul-2011>, 0.419866941013046),
(<U : 01-Aug-2011>, 0.73489099683479775),
(<U : 01-Sep-2011>, 0.7040093508897648)]
In [18]
More information about the SciPy-Dev
mailing list