Additional util functions

class darts.utils.utils.ModelMode(value)[source]

Bases: Enum

An enumeration.

ADDITIVE = 'additive'
MULTIPLICATIVE = 'multiplicative'
NONE = None
class darts.utils.utils.SeasonalityMode(value)[source]

Bases: Enum

An enumeration.

ADDITIVE = 'additive'
MULTIPLICATIVE = 'multiplicative'
NONE = None
class darts.utils.utils.TrendMode(value)[source]

Bases: Enum

An enumeration.

EXPONENTIAL = 'exponential'
LINEAR = 'linear'
darts.utils.utils.drop_after_index(index, split_point)[source]

Drops everything after the provided time split_point (excluded) from the index.

Parameters
  • index (Union[RangeIndex, DatetimeIndex]) – The index to drop values from.

  • split_point (Union[int, Timestamp]) – The timestamp that indicates cut-off time.

Returns

A new index with values after split_point dropped.

Return type

Union[pd.RangeIndex, pd.DatetimeIndex]

darts.utils.utils.drop_before_index(index, split_point)[source]

Drops everything before the provided time split_point (excluded) from the index.

Parameters
  • index (Union[RangeIndex, DatetimeIndex]) – The index to drop values from.

  • split_point (Union[int, Timestamp]) – The timestamp that indicates cut-off time.

Returns

A new index with values before split_point dropped.

Return type

Union[pd.RangeIndex, pd.DatetimeIndex]

darts.utils.utils.generate_index(start=None, end=None, length=None, freq=None, name=None)[source]

Returns an index with a given start point and length. Either a pandas DatetimeIndex with given frequency or a pandas RangeIndex. The index starts at

Parameters
  • start (Union[Timestamp, int, None]) – The start of the returned index. If a pandas Timestamp is passed, the index will be a pandas DatetimeIndex. If an integer is passed, the index will be a pandas RangeIndex index. Works only with either length or end.

  • end (Union[Timestamp, int, None]) – Optionally, the end of the returned index. Works only with either start or length. If start is set, end must be of same type as start. Else, it can be either a pandas Timestamp or an integer.

  • length (Optional[int]) – Optionally, the length of the returned index. Works only with either start or end.

  • freq (Union[str, int, DateOffset, None]) – The time difference between two adjacent entries in the returned index. In case start is a timestamp, a DateOffset alias is expected; see docs. By default, “D” (daily) is used. If start is an integer, freq will be interpreted as the step size in the underlying RangeIndex. The freq is optional for generating an integer index (if not specified, 1 is used).

  • name (Optional[str]) – Optionally, an index name.

Return type

Union[DatetimeIndex, RangeIndex]

darts.utils.utils.n_steps_between(end, start, freq)[source]

Get the number of time steps with a given frequency freq between end and start. Works for both integers and time stamps.

  • if end, start, freq are all integers, we can simple divide the difference by the frequency.

  • if freq is a pandas Dateoffset with non-ambiguous timedelate (e.g. “d”, “h”, …, and not “M”, “Y”, …),

    we can simply divide by the frequency

  • otherwise, we take the period difference between the two time stamps.

Parameters
  • end (Union[Timestamp, int]) – The end pandas Timestamp / integer.

  • start (Union[Timestamp, int]) – The start pandas Timestamp / integer.

  • freq (Union[DateOffset, int, str]) – The frequency / step size.

Returns

The number of steps/periods between end and start with a given frequency freq.

Return type

int

Examples

>>> n_steps_between(start=pd.Timestamp("2000-01-01"), end=pd.Timestamp("2000-03-01"), freq="M")
2
>>> n_steps_between(start=0, end=2, freq=1)
2
>>> n_steps_between(start=0, end=2, freq=2)
1
darts.utils.utils.slice_index(index, start, end)[source]

Returns a new Index with the same type as the input index, containing the values between start and end included. If start and end are not in the index, the closest values are used instead. The start and end values can be either integers (in which case they are interpreted as indices), or pd.Timestamps (in which case they are interpreted as actual timestamps).

Parameters
  • index (Union[RangeIndex, DatetimeIndex]) – The index to slice.

  • start (Union[int, Timestamp]) – The start of the returned index.

  • end (Union[int, Timestamp]) – The end of the returned index.

Returns

A new index with the same type as the input index, but with only the values between start and end included.

Return type

Union[pd.RangeIndex, pd.DatetimeIndex]