This Page

Quick search

Defines a ndarray of dates, as ordinals.
The dates parameter must then be a sequence of Date
objects or a sequence of integers.
The freq parameter must be a valid frequency specification,
as listed in the Frequency constants section.

When viewed globally (array-wise), a DateArray object behaves as an
ndarray of integers.
When viewed element-wise, DateArray behaves as a standard sequence of
Date objects.

Thus, a test such as:

>>> DateArray(...)==value

is valid only if value is an integer, not a Date object.
In that case, the test returns a boolean ndarray that has
the same shape as the DateArray object.

The only requirement for the Date elements of a DateArray is
that they must have the same frequency.
Otherwise, they do not have to be in chronological order nor to be regularly
spaced, and duplicated entries are also permitted.

As subclasses of ndarray, DateArray objects follow
the same rules for accessing elements through
indexing.
In addition, DateArray objects can be indexed with one or several
Date objects.

When a single element of a DateArray is accessed,
the result is a Date object with the same frequency as the input.
Otherwise, the result is a DateArray with the same frequency
as the input.
Note that when using a slice to access specific elements
of a DateArray, the result is always a DateArray.

>>> dates=ts.date_array(start_date=ts.Date('M','2001-01'),length=36)>>> # Accessing a single element with an integer>>> dates[0]<M : Jan-2001>>>> # Accessing a single element with a Date object>>> dates[ts.Date('M','2002-01')]<M : Jan-2002>>>> # Using a slice to access a single element : the result is a DateArray>>> dates[-1:]DateArray([Dec-2003], freq='M')>>> # Accessing multiple elements with a list of integers>>> dates[[0,12,24]]DateArray([Jan-2001, Jan-2002, Jan-2003], freq='M')>>> # Accessing multiple elements with a list of Date objects>>> dates[[ts.Date('M','2002-01'),ts.Date('M','2003-01')]]DateArray([Jan-2002, Jan-2003], freq='M')

Arithmetic operations on DateArray objects are limited to additions
and subtractions.
Any other arithmetic operation will raise a ArithmeticDateError exception.

Adding (subtracting) a scalar or a sequence of scalars to (from)
a DateArray returns a DateArray with the same frequency.
The shapes of the inputs must be compatible, as described in the
broadcasting
section of the Numpy
documentation.

Adding (subtracting) two DateArray or a DateArray and
a Date is possible only if the two objects have the same frequency.
The result is then a ndarray.
If the inputs do not share the same frequency,
a FrequencyDateError exception is raised.

The _cachedinfo attribute is a directory storing some information
about the instance.
It has the following keys:

'chronidx':{None, ndarray}

If not None, a ndarray of integers corresponding
to the indices sorting the instance in chronological order.
If the DateArray is already sorted chronologically, then
_cachedinfo[‘chronidx’] = np.array([], dtype=int)