gluonts.zebras package#

class gluonts.zebras.BatchSplitFrame(_past: 'dict', _future: 'dict', index: 'List[Optional[Periods]]', static: 'dict', past_length: 'int', future_length: 'int', tdims: 'dict', metadata: 'List[Optional[dict]]', _pad: 'List[Pad]')[source]#

Bases: object

as_dict()[source]#
property batch_size#
property future#
future_length: int#
index: List[Optional[gluonts.zebras._period.Periods]]#
items()[source]#
metadata: List[Optional[dict]]#
property past#
past_length: int#
static: dict#
tdims: dict#
class gluonts.zebras.BatchTimeFrame(columns: 'dict', index: 'Collection[Optional[Periods]]', static: 'dict', length: 'int', tdims: 'dict', metadata: 'Collection[Optional[dict]]', _pad: 'Collection[Pad]')[source]#

Bases: object

as_dict(prefix=None, static=True)[source]#
property batch_size#
columns: dict#
index: Collection[Optional[gluonts.zebras._period.Periods]]#
items()[source]#
length: int#
like(columns=None, static=None, tdims=None)[source]#
metadata: Collection[Optional[dict]]#
static: dict#
tdims: dict#
class gluonts.zebras.BatchTimeSeries(values: 'np.ndarray', index: 'List[Optional[Periods]]', name: 'List[Optional[str]]', tdim: 'int', metadata: 'List[Optional[dict]]', _pad: 'List[Pad]')[source]#

Bases: gluonts.zebras._base.TimeBase

property batch_size#
index: List[Optional[gluonts.zebras._period.Periods]]#
items()[source]#
like(values: numpy.ndarray, name: Optional[str] = None)[source]#
metadata: List[Optional[dict]]#
name: List[Optional[str]]#
pad(value, left: int = 0, right: int = 0) gluonts.zebras._time_series.TimeSeries[source]#
property shape: Tuple[int, ...]#
tdim: int#
values: numpy.ndarray#
class gluonts.zebras.Freq(name: str, n: int, suffix: Optional[str] = None)[source]#

Bases: object

A class representing frequencies, such as n-days.

Note: Use freq to construct instances of Freq.

We use frequency aliases from pandas over frequency names defined by numpy. For example, the name for minutely is either “min” or “T”, while “m” and “M” represent monthly frequencies. In contrast numpy uses “m” for minutely and “M” for monthly. In addition, pandas defines some frequencies which do not exist in numpy, for example quarterly frequencies.

However, internally we use numpy.datetime64 objects and thus we must support numpy’s frequency names as well. To do this we generally use base frequencies (multiple = 1), since numpy otherwise aligns timestamps for us which we don’t want.

Weekly frequency needs to be handled specially, since numpy counts the number of weeks since Thu Jan 1 1970 and uses Thursday and aligns the timestamp to Thursday. We therefore use daily frequency internally and align to Monday.

align(timestamp: numpy.datetime64) numpy.datetime64[source]#

Align timestamp according to the frequency.

For example, for daily frequency, any timestamps that fall into the same day align to the same value.

classmethod from_pandas(freq) gluonts.zebras._freq.Freq[source]#
n: int#
name: str#
property np_freq: Tuple[str, int]#
range(start: numpy.datetime64, count: int) numpy.ndarray[source]#
shift(start: numpy.datetime64, count: int) numpy.datetime64[source]#
property step#
suffix: Optional[str] = None#
to_pandas()[source]#
class gluonts.zebras.Period(data: 'np.datetime64', freq: 'Freq')[source]#

Bases: gluonts.zebras._period._BasePeriod

data: numpy.datetime64#
freq: gluonts.zebras._freq.Freq#
periods(count: int)[source]#
property shape: Tuple[int, ...]#
to_numpy() numpy.datetime64[source]#
to_pandas()[source]#
to_timestamp()[source]#
unix_epoch() int[source]#
class gluonts.zebras.Periods(data: 'np.ndarray', freq: 'Freq')[source]#

Bases: gluonts.zebras._period._BasePeriod

data: numpy.ndarray#
property end: gluonts.zebras._period.Period#

Last timestamp.

>>> p = periods("2021", "D", 365)
>>> assert p.end == period("2021-12-31", "D")
extend(count: int) gluonts.zebras._period.Periods[source]#

Copy which contains count future timestamps.

>>> p = periods("2021", "D", 365)
>>> assert p.extend(5) == periods("2021", "D", 370)
freq: gluonts.zebras._freq.Freq#
classmethod from_pandas(index)[source]#

Turn pandas.PeriodIndex or pandas.DatetimeIndex into Periods.

future(count: int) gluonts.zebras._period.Periods[source]#

Next count timestamps.

>>> p = periods("2021", "D", 365)
>>> assert p.future(5) == periods("2022-01-01", "D", 5)
head(count: int) gluonts.zebras._period.Periods[source]#

First count timestamps.

>>> p = periods("2021", "D", 365)
>>> assert p.head(5) == periods("2021-01-01", "D", 5)
index_of(period: Union[str, gluonts.zebras._period.Period])[source]#

Return the index of period

>>> p = periods("2021", "D", 365)
>>> assert p.index_of(period("2021-02-01", "D")) == 31
intersection(other)[source]#
past(count: int) gluonts.zebras._period.Periods[source]#

Previous count timestamps.

>>> p = periods("2021", "D", 365)
>>> assert p.past(5) == periods("2020-12-27", "D", 5)
prepend(count: int) gluonts.zebras._period.Periods[source]#

Copy which contains count past timestamps.

>>> p = periods("2021", "D", 365)
>>> assert p.prepend(5) == periods("2020-12-27", "D", 370)
property shape: Tuple[int, ...]#
property start: gluonts.zebras._period.Period#
tail(count: int) gluonts.zebras._period.Periods[source]#

Last count timestamps.

>>> p = periods("2021", "D", 365)
>>> assert p.tail(5) == periods("2021-12-27", "D", 5)
to_numpy() numpy.ndarray[source]#
to_pandas()[source]#
unix_epoch() numpy.ndarray[source]#
class gluonts.zebras.SplitFrame(_past: 'dict', _future: 'dict', index: 'Optional[Periods]', static: 'dict', past_length: 'int', future_length: 'int', tdims: 'dict', metadata: 'Optional[dict]' = None, default_tdim: 'int' = - 1, _pad: 'Pad' = Pad(left=0, right=0))[source]#

Bases: object

as_dict()[source]#
default_tdim: int = -1#
property future#
future_length: int#
index: Optional[gluonts.zebras._period.Periods]#
metadata: Optional[dict] = None#
property past#
past_length: int#
remove(column)[source]#
resize(past_length: Optional[int] = None, future_length: Optional[int] = None, pad_value=0.0) gluonts.zebras._split_frame.SplitFrame[source]#
set(name, value, tdim=None)[source]#
set_future(name, value, tdim=None)[source]#
set_like(ref: str, column, value, tdim=None)[source]#
set_past(name, value, tdim=None)[source]#
static: dict#
tdims: dict#
with_index(index)[source]#
class gluonts.zebras.TimeFrame(columns: 'dict', index: 'Optional[Periods]', static: 'dict', length: 'int', tdims: 'dict', metadata: 'Optional[dict]' = None, default_tdim: 'int' = - 1, _pad: 'Pad' = Pad(left=0, right=0))[source]#

Bases: gluonts.zebras._base.TimeBase

apply(fn, columns=None)[source]#
as_dict(prefix=None, static=True)[source]#
astype(type, columns=None) gluonts.zebras._time_frame.TimeFrame[source]#
columns: dict#
default_tdim: int = -1#
eq_shape(other: gluonts.zebras._time_frame.TimeFrame) bool[source]#
eq_to(other: gluonts.zebras._time_frame.TimeFrame) bool[source]#
classmethod from_pandas(df)[source]#

Turn pandas.DataFrame into TimeFrame.

index: Optional[gluonts.zebras._period.Periods]#
length: int#
like(columns=None, static=None)[source]#
metadata: Optional[dict] = None#
pad(value, left: int = 0, right: int = 0) gluonts.zebras._time_frame.TimeFrame[source]#
remove(column)[source]#
remove_static(name)[source]#
rename(mapping=None, **kwargs)[source]#

Rename columns of TimeFrame.

The keys in mapping denote the target column names, i.e. rename({"target": "source"}). For convenience one can use keyword parameters (`.rename(target=”source”)).

rename_static(mapping=None, **kwargs)[source]#

Rename static fields of TimeFrame.

The keys in mapping denote the target column names, i.e. rename({"target": "source"}). For convenience one can use keyword parameters (`.rename(target=”source”)).

rolsplit(index, *, distance: int = 1, past_length: Optional[int] = None, future_length: Optional[int] = None, n: Optional[int] = None, pad_value=0.0)[source]#

Create rolling split of past/future pairs.

Parameters
  • index – Starting index that denominates the cut off point from which splits are generated.

  • distance – The distance by which pairs are shifted. Defaults to 1. To avoid overlapping examples, distance has to be set to be at least past_length.

  • future_length – Optionally enforce future length. Note that rolsplit will never pad values in the future range.

  • optional – Optionally enforce future length. Note that rolsplit will never pad values in the future range.

  • past_length – If provided, all pairs past will have past_length, padded with pad_value if needed.

  • optional – If provided, all pairs past will have past_length, padded with pad_value if needed.

  • n – If provided, limits the number of pairs to n.

  • optional – If provided, limits the number of pairs to n.

  • pad_value – Value to pad past if needed, defaults to 0.0.

Return type

A stream of zebras.SplitFrame objects.

set(name, value, tdim=None)[source]#
set_like(ref: str, column, value, tdim=None)[source]#
set_static(name, value)[source]#
split(index, past_length=None, future_length=None, pad_value=0.0)[source]#
stack(select: List[str], into: str, drop: bool = True) gluonts.zebras._time_frame.TimeFrame[source]#
static: dict#
tdims: dict#
class gluonts.zebras.TimeSeries(values: 'np.ndarray', index: 'Optional[Periods]' = None, name: 'Optional[str]' = None, tdim: 'int' = - 1, metadata: 'Optional[dict]' = None, _pad: 'Pad' = Pad(left=0, right=0))[source]#

Bases: gluonts.zebras._base.TimeBase

index: Optional[gluonts.zebras._period.Periods] = None#
metadata: Optional[dict] = None#
name: Optional[str] = None#
pad(value, left: int = 0, right: int = 0) gluonts.zebras._time_series.TimeSeries[source]#
plot()[source]#
property shape: Tuple[int, ...]#
tdim: int = -1#
to_numpy()[source]#
values: numpy.ndarray#
gluonts.zebras.freq(arg) gluonts.zebras._freq.Freq[source]#
gluonts.zebras.period(data: Union[gluonts.zebras._period.Period, str], freq: Optional[Union[gluonts.zebras._freq.Freq, str]] = None) gluonts.zebras._period.Period[source]#

Create a zebras.Period object that represents a period of time.

Parameters
  • data – The time period represented by a string (e.g., “2023-01-01”), or another Period object.

  • freq – The frequency of the period, e.g, “H” for hourly, by default None.

  • optional – The frequency of the period, e.g, “H” for hourly, by default None.

Return type

A zebras.Period object.

gluonts.zebras.periods(start: Union[gluonts.zebras._period.Period, str], freq: Union[gluonts.zebras._freq.Freq, str], count: int) gluonts.zebras._period.Period[source]#

Create a zebras.Periods object that represents multiple consecutive periods of time.

Parameters
  • start – The starting time period represented by a string (e.g., “2023-01-01”), or another Period object.

  • freq – The frequency of the period, e.g, “H” for hourly.

  • count – The number of periods.

Return type

A zebras.Periods object.

gluonts.zebras.split_frame(full=None, *, past=None, future=None, past_length=None, future_length=None, static=None, index=None, start=None, freq=None, tdims=None, metadata=None, default_tdim=- 1)[source]#

Create a zebras.SplitFrame where columns can either be past, future or full, which spans both past and future.

past_length and future_length is derived from the input data if possible or default to 0 in case no respective data is available. It is possible to set these values explicitly for enforcing consistency or to provide a length even though no time series spans that range.

Parameters
  • full – Time series columns that span past and future.

  • optional – Time series columns that span past and future.

  • past – Time series columns that are past only.

  • optional – Time series columns that are past only.

  • future – Time series columns that are future only.

  • optional – Time series columns that are future only.

  • past_length – Set length of the past section, derived from data if not provided.

  • optional – Set length of the past section, derived from data if not provided.

  • future_length – Set length of the future section, derived from data if not provided.

  • optional – Set length of the future section, derived from data if not provided.

  • static – Values that are independent of time.

  • optional – Values that are independent of time.

  • index – A zebras.Periods object representing timestamps. Must have the same length as full range.

  • optional – A zebras.Periods object representing timestamps. Must have the same length as full range.

  • start – The start time represented by a string (e.g., “2023-01-01”), or a zebras.Period object. An index will be constructed using this start time and the specified frequency

  • optional – The start time represented by a string (e.g., “2023-01-01”), or a zebras.Period object. An index will be constructed using this start time and the specified frequency

  • freq – The frequency to use for constructing the index.

  • optional – The frequency to use for constructing the index.

  • tdims – A dictionary specifying the time dimension for each column, this applies to past, future and full.

  • optional – A dictionary specifying the time dimension for each column, this applies to past, future and full.

  • default_tdim – The default time dimension, by default -1

  • optional – The default time dimension, by default -1

  • metadata – A dictionary of metadata associated with the TimeFrame, by default None

  • optional – A dictionary of metadata associated with the TimeFrame, by default None

Return type

A zebras.SplitFrame object.

gluonts.zebras.time_frame(columns: Optional[Mapping[str, Collection]] = None, *, index: Optional[gluonts.zebras._period.Periods] = None, start: Optional[Union[gluonts.zebras._period.Period, str]] = None, freq: Optional[Union[gluonts.zebras._freq.Freq, str]] = None, static: Optional[Mapping[str, Any]] = None, tdims: Optional[Mapping[str, int]] = None, length: Optional[int] = None, default_tdim: int = - 1, metadata: Optional[Mapping] = None)[source]#

Create a zebras.TimeFrame object that represents one or more time series.

Parameters
  • columns – A dictionary where keys are strings representing column names and values are sequences (e.g., list, numpy arrays). All columns must have the same length in the time dimension, by default None

  • optional – A dictionary where keys are strings representing column names and values are sequences (e.g., list, numpy arrays). All columns must have the same length in the time dimension, by default None

  • index – A zebras.Periods object representing timestamps. Must have the same length as the columns, by default None

  • optional – A zebras.Periods object representing timestamps. Must have the same length as the columns, by default None

  • start – The start time represented by a string (e.g., “2023-01-01”), or a zebras.Period object. An index will be constructed using this start time and the specified frequency, by default None

  • optional – The start time represented by a string (e.g., “2023-01-01”), or a zebras.Period object. An index will be constructed using this start time and the specified frequency, by default None

  • freq – The frequency of the period, e.g, “H” for hourly, by default None

  • optional – The frequency of the period, e.g, “H” for hourly, by default None

  • static – A dictionary of static-in-time features, by default None

  • optional – A dictionary of static-in-time features, by default None

  • tdims – A dictionary specifying the time dimension for each column. The keys should match those in columns. If unspecified for a column, the default_tdim is used, by default None

  • optional – A dictionary specifying the time dimension for each column. The keys should match those in columns. If unspecified for a column, the default_tdim is used, by default None

  • length – The length (in time) of the TimeFrame, by default None

  • optional – The length (in time) of the TimeFrame, by default None

  • default_tdim – The default time dimension, by default -1

  • optional – The default time dimension, by default -1

  • metadata – A dictionary of metadata associated with the TimeFrame, by default None

  • optional – A dictionary of metadata associated with the TimeFrame, by default None

Return type

A zebras.TimeFrame object.

gluonts.zebras.time_series(values: Collection, *, index: Optional[gluonts.zebras._period.Periods] = None, start: Optional[Union[gluonts.zebras._period.Period, str]] = None, freq: Optional[str] = None, tdim: int = - 1, name: Optional[str] = None, metadata: Optional[Dict] = None)[source]#

Create a zebras.TimeSeries object that represents a time series.

Parameters
  • values – A sequence (e.g., list, numpy arrays) representing the values of the time series.

  • index – A zebras.Periods object representing timestamps. Must have the same length as the values, by default None

  • optional – A zebras.Periods object representing timestamps. Must have the same length as the values, by default None

  • start – The start time represented by a string (e.g., “2023-01-01”), or a zebras.Period object. An index will be constructed using this start time and the specificed frequency, by default None

  • optional – The start time represented by a string (e.g., “2023-01-01”), or a zebras.Period object. An index will be constructed using this start time and the specificed frequency, by default None

  • freq – The frequency of the period, e.g, “H” for hourly, by default None

  • optional – The frequency of the period, e.g, “H” for hourly, by default None

  • tdim – The time dimension in values, by default -1

  • optional – The time dimension in values, by default -1

  • name (optional) – A description for the time series. This will be the column names when returned from a TimeFrame.

  • metadata – A dictionary of metadata associated with the time series, by default None

  • optional – A dictionary of metadata associated with the time series, by default None

Return type

A zebras.TimeSeries object.