Additional util functions¶
- class darts.utils.ts_utils.SeriesType(value)[source]¶
Bases:
Enum
An Enum for different TimeSeries sequence types.
- NONE = -1¶
- SEQ = 1¶
- SEQ_SEQ = 2¶
- SINGLE = 0¶
- darts.utils.ts_utils.get_series_seq_type(ts)[source]¶
Returns the sequence type of ts.
SeriesType.SINGLE: TimeSeries (e.g. a single series)
SeriesType.SEQ: sequence of TimeSeries (e.g. multiple series)
SeriesType.SEQ_SEQ: sequence of sequences of TimeSeries (e.g. historical forecasts output)
- Parameters
ts (
Union
[TimeSeries
,Sequence
[TimeSeries
],Sequence
[Sequence
[TimeSeries
]]]) – The input series to get the sequence type from.- Raises
ValueError – If ts does not have one of the expected sequence types.
- Return type
- darts.utils.ts_utils.get_single_series(ts)[source]¶
Returns a single (first) TimeSeries or None from ts. Returns ts if ts is a TimeSeries, ts[0] if ts is a Sequence[TimeSeries], and ts[0][0] if ts is a Sequence[Sequence[TimeSeries]]. Otherwise, returns None.
- Parameters
ts (
Union
[TimeSeries
,Sequence
[TimeSeries
],Sequence
[Sequence
[TimeSeries
]],None
]) – None, a single TimeSeries, a sequence of TimeSeries, or a sequence of sequences of TimeSeries.- Returns
ts if ts is a TimeSeries, ts[0] if ts is a Sequence of TimeSeries. Otherwise, returns None
- Return type
- darts.utils.ts_utils.retain_period_common_to_all(series)[source]¶
Trims all series in the provided list, if necessary, so that the returned time series have a common span (corresponding to largest time sub-interval common to all series).
- Parameters
series (
List
[TimeSeries
]) – The list of series to consider.- Raises
ValueError – If no common time sub-interval exists
- Returns
A list of series, where each series have the same span
- Return type
List[TimeSeries]
- darts.utils.ts_utils.seq2series(ts)[source]¶
If ts is a Sequence with only a single series, return the single series as TimeSeries.
- Parameters
ts (
Union
[TimeSeries
,Sequence
[TimeSeries
],None
]) – None, a single TimeSeries, or a sequence of TimeSeries- Return type
ts if ts if is not a single element TimeSeries sequence, else ts[0]
- darts.utils.ts_utils.series2seq(ts, seq_type_out=SeriesType.SEQ, nested=False)[source]¶
If possible, converts ts into the desired sequence type seq_type_out. Otherwise, returns the original ts.
- Parameters
ts (
Union
[TimeSeries
,Sequence
[TimeSeries
],Sequence
[Sequence
[TimeSeries
]],None
]) – None, a single TimeSeries, a sequence of TimeSeries, or a sequence of sequences of TimeSeries.seq_type_out (
SeriesType
) –The output sequence type:
SeriesType.SINGLE: TimeSeries (e.g. a single series)
SeriesType.SEQ: sequence of TimeSeries (e.g. multiple series)
SeriesType.SEQ_SEQ: sequence of sequences of TimeSeries (e.g. historical forecasts output)
nested (
bool
) – Only applies with seq_type_out=SeriesType.SEQ_SEQ and ts having a sequence type SeriesType.SEQ. In this case, wrap each element in ts in a list ([ts1, ts2] -> [[ts1], [ts2]]).
- Raises
ValueError – If there is an invalid seq_type_out value.
- Return type
Union
[TimeSeries
,Sequence
[TimeSeries
],Sequence
[Sequence
[TimeSeries
]],None
]