[SciPy-User] scikits.timeseries question

Robert Ferrell ferrell@diablotech....
Mon Nov 30 23:32:14 CST 2009


On Nov 30, 2009, at 9:03 PM, Pierre GM wrote:

> On Nov 30, 2009, at 9:59 PM, Robert Ferrell wrote:
>
>> 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.
>
> Well, keep in mind that Date was implemented a few years ago  
> already, far before the new datetime64 dtype, and it was the easiest  
> way we had to define a new datatype (well, a kind of datatype). I'll  
> check how we can merge the two approaches when I'll have some time.
> Anyhow, in practice, a Date object will be seen as a np.object by  
> numpy, and you end up having a ndarray with a np.object dtype.

Since a DateArray has more methods than a bare np.array, it would  
surprise me if an array of Dates were a DateArray.  That's why it  
seems natural that np.array + Date = np.array.  I think that behavior  
will continue, right?

In any case, I find the timeseries scikit very useful, and while  
there's always room for improvement, as it is you & Matt did a great  
job.

>
>> 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)
>
> Wow, that's overkill ! Just make sd a DateArray:
>>>> np.arange(4) + ts.DateArray(sd)
>
> Now, because DateArray is a subclass of ndarray with a higher  
> priority, its _add__ method takes over and the ouput is a DateArray.

Of course.  I was just trying to show something by example.  (For  
silly reasons,  I  avoid the np.array + DateArray construct.  A few  
times I have mistakenly made DateArray + DateArray constructs  
(forgetting I'd already promoted the first argument to a DateArray),  
which rarely gives me what I want/expect.  Silly, yes, but I code with  
the brain I have, not the brain I wish I had:)

>
>>
>>> 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
>
>
> What version are you using ? And anyway, you get the exception only  
> if you try to print it (as strftime is called only when calling repr/ 
> str)

In [178]: ts.__version__
Out[178]: '0.67.0.dev-r1570'




More information about the SciPy-User mailing list