[SciPy-User] scikits.timeseries question
Mon Nov 30 22:13:55 CST 2009
Christopher Barker <Chris.Barker <at> noaa.gov> writes:
> >> In : da = ts.date_array((1,2,3,4), start_date=sd)
> > Check the doc for date_array: the first argument can be
> > * an existing :class:`DateArray` object;
> > * a sequence of :class:`Date` objects with the same frequency;
> > * a sequence of :class:`datetime.datetime` objects;
> > * a sequence of dates in string format;
> > * a sequence of integers corresponding to the representation of
> > :class:`Date` objects.
> That's what I have: a sequence of integers corresponding to the
> representation of the Date objects (doesn't it represent them as "units
> since start date" where units is the "freq" ?
> If that's not what if means, then what does it mean?
I agree the documentation is perhaps a bit confusing here. The sequence of
integers being referred to are the internal representation of the Date objects
(eg. ts.now('d').value) which is absolute, not relative (not relative to a
custom start date anyway). Another thing you are missing is that the first
argument (dlist) is not supposed to be used in conjunction with the start_date
There are a couple ways to call date_array:
1. using the `dlist` argument, possibly in combination with the `freq` argument
if freq is not implicit with the dlist being passed.
2. Using the `start_date` parameter in combination with either the `length` or
`end_date` parameter. This option would only be used for a continuous time
series (ie. no missing or duplicated dates)
Whether this is a good api is probably debateable, but that is how it works
In addition to the methods described by Pierre and Robert, you could also do:
>>> sd = ts.now('d')
>>> relative_days = np.array([1,5,8])
>>> absolute_days = relative_days + sd.value
>>> darray = ts.date_array(absolute_days, freq = sd.freq)
which I think probably has the lowest overhead (but don't hold me to that :) )
if that matters for your application.
More information about the SciPy-User