[SciPy-User] scikits.timeseries question

Robert Ferrell ferrell@diablotech....
Mon Nov 30 20:59:32 CST 2009

On Nov 30, 2009, at 6:16 PM, Christopher Barker wrote:

> Pierre GM wrote:
>> Ah OK. Well, the answer is: that depends. iIf you know that your
>> dates are just in daily increments from 2001-01-01 (like a range),
>> then just use start_date and length.
> right -- but I don't know that.
>> If you may have several duplicated dates (like 2001-01-01,
>> 2001-01-02, 2001-01-02, 2001-01-03...), then the easiest is probably:
>>>>> da = ts.date_array(np.array(0,1,1,2)+sd)
> nope -- not duplicated, but maybe there are missing ones. The point is
> that I have an array of "days since", and I want array of
> timeseries.dates (which is a DateArray, yes?)

I don't think so.  An array of dates is not a DateArray.

In [98]: sd = ts.Date('d', '2001-01-01')

In [99]: zeros(4) + sd
Out[99]: array([01-Jan-2001, 01-Jan-2001, 01-Jan-2001, 01-Jan-2001],  

This seems natural to me, (array + Date = array) although I do have to  
include an extra line sometimes to get a DateArray if I need it.  If I  
need a timeseries, sometimes I can skip making the DateArray explicitly.

In [109]: a = arange(4) + sd

In [110]: a
Out[110]: array([01-Jan-2001, 02-Jan-2001, 03-Jan-2001, 04-Jan-2001],  

In [111]: ts.time_series([1,2,3,4], dates=a)
timeseries([1 2 3 4],
            dates = [01-Jan-2001 ... 04-Jan-2001],
            freq  = D)

>> np.array(...) + sd gives you a ndarray of Date objects (so its dtype
>> is np.object), and you use that as the input of date_array. The
>> frequency should be recognized properly.
> OK -- though it seems I SHOULD be able to go straight to an DateArray,

Is the issue that sd is a Date and not a DateArray?  You can always  
make a DataArray with sd, of the correct length, and then add to that:

In [83]: sd = ts.Date('d', '2001-01-01')

In [84]: d1 = ts.date_array(zeros(4) + sd)

In [85]: d1
DateArray([01-Jan-2001, 01-Jan-2001, 01-Jan-2001, 01-Jan-2001],

In [86]: d1 + array([0,2,3,5])
DateArray([01-Jan-2001, 03-Jan-2001, 04-Jan-2001, 06-Jan-2001],

I'm probably telling you things that are obvious and are not  
addressing your question.

> and I'm still confused about what this means:
>>> In [43]: da = ts.date_array((1,2,3,4), start_date=sd)

This throws an exception for me.

<type 'exceptions.ValueError'>: year=1 is before 1900; the datetime  
strftime() methods require year >= 1900


More information about the SciPy-User mailing list