Timeseries

TimeSeries is the main class in darts. It represents a univariate or multivariate time series. It can represent a stochastic time series by storing several samples (trajectories).

class darts.timeseries.TimeSeries(xa: xarray.core.dataarray.DataArray)[source]

Bases: object

Wrapper around a (well formed) DataArray. Use the static factory methods to build instances unless you know what you are doing.

static _fill_missing_dates(xa: xarray.core.dataarray.DataArray, freq: Optional[str] = None) → xarray.core.dataarray.DataArray[source]

Returns an xarray DataArray instance with missing dates inserted from an input xarray DataArray. The first dimension of the input DataArray xa has to be the time dimension.

This requires either a provided freq or the possibility to infer a unique frequency (see offset aliases for more info on supported frequencies) from the provided timestamps.

Parameters
  • xa – The xarray DataArray

  • freq – Optionally, a string representing the frequency of the Pandas DateTimeIndex to fill in the missing dates.

Raises

ValueError – If xa’s DateTimeIndex contains less than 3 elements; if no unique frequency can be inferred from xa’s DateTimeIndex; if the resampled DateTimeIndex does not contain all dates from xa (see _restore_xarray_from_frequency())

Returns

xarray DataArray with filled missing dates from xa

Return type

xarray DataArray

static _restore_xarray_from_frequency(xa: xarray.core.dataarray.DataArray, freq: str) → xarray.core.dataarray.DataArray[source]

Returns an xarray DataArray instance that is resampled from an input xarray DataArray xa with frequency freq. freq should be the inferred or actual frequency of xa. All data from xa is maintained in the output DataArray at the corresponding dates. Any missing dates from xa will be inserted into the returned DataArray with np.nan values.

The first dimension of the input DataArray xa has to be the time dimension.

This requires a provided freq (see offset aliases for more info on supported frequencies).

Parameters
  • xa – The xarray DataArray

  • freq – A string representing the actual or inferred frequency of the Pandas DateTimeIndex from xa.

Raises

ValueError – If the resampled DateTimeIndex does not contain all dates from xa

Returns

xarray DataArray resampled from xa with freq including all data from xa and inserted missing dates

Return type

xarray DataArray

add_datetime_attribute(attribute, one_hot: bool = False, cyclic: bool = False)darts.timeseries.TimeSeries[source]

Returns a new TimeSeries instance with one (or more) additional component(s) that contain an attribute of the time index of the current series specified with attribute, such as ‘weekday’, ‘day’ or ‘month’.

This works only for deterministic time series (i.e., made of 1 sample).

Parameters
  • attribute – A pd.DatatimeIndex attribute which will serve as the basis of the new column(s).

  • one_hot – Boolean value indicating whether to add the specified attribute as a one hot encoding (results in more columns).

  • cyclic – Boolean value indicating whether to add the specified attribute as a cyclic encoding. Alternative to one_hot encoding, enable only one of the two. (adds 2 columns, corresponding to sin and cos transformation).

Returns

New TimeSeries instance enhanced by attribute.

Return type

TimeSeries

add_holidays(country_code: str, prov: str = None, state: str = None)darts.timeseries.TimeSeries[source]

Adds a binary univariate component to the current series that equals 1 at every index that corresponds to selected country’s holiday, and 0 otherwise. The frequency of the TimeSeries is daily.

Available countries can be found here.

This works only for deterministic time series (i.e., made of 1 sample).

Parameters
  • country_code – The country ISO code

  • prov – The province

  • state – The state

Returns

A new TimeSeries instance, enhanced with binary holiday component.

Return type

TimeSeries

all_values(copy=True) → numpy.ndarray[source]

Returns a 3-D Numpy array of dimension (time, component, sample), containing this series’ values for all samples.

Parameters

copy – Whether to return a copy of the values, otherwise returns a view. Leave it to True unless you know what you are doing.

Returns

The values composing the time series.

Return type

numpy.ndarray

append(other: darts.timeseries.TimeSeries)darts.timeseries.TimeSeries[source]

Appends another TimeSeries to this TimeSeries, along the time axis.

Parameters

other – A second TimeSeries.

Returns

A new TimeSeries, obtained by appending the second TimeSeries to the first.

Return type

TimeSeries

append_values(values: numpy.ndarray)darts.timeseries.TimeSeries[source]

Appends values to current TimeSeries, to the given indices.

Parameters

values – An array with the values to append.

Returns

A new TimeSeries with the new values appended

Return type

TimeSeries

autocorr(lag=1) → float[source]
property columns

Same as components property

property components

The names of the components (equivalent to DataFrame columns) as a Pandas Index

copy()darts.timeseries.TimeSeries[source]

Make a copy of this time series object

Returns

A copy of this time series.

Return type

TimeSeries

data_array(copy=True) → xarray.core.dataarray.DataArray[source]

Returns the xarray DataArray representation of this time series.

Parameters

copy – Whether to return a copy of the series. Leave it to True unless you know what you are doing.

Returns

The xarray DataArray underlying this time series.

Return type

xarray.DataArray

describe(percentiles=None, include=None, exclude=None) → pandas.core.frame.DataFrame[source]
diff(n: Optional[int] = 1, periods: Optional[int] = 1, dropna: Optional[bool] = True)darts.timeseries.TimeSeries[source]

Returns a differenced time series. This is often used to make a time series stationary.

Parameters
  • n – Optionally, a positive integer indicating the number of differencing steps (default = 1). For instance, n=2 computes the second order differences.

  • periods – Optionally, periods to shift for calculating difference. For instance, periods=12 computes the difference between values at time t and times t-12.

  • dropna – Whether to drop the missing values after each differencing steps. If set to False, the corresponding first periods time steps will be filled with NaNs.

Returns

A TimeSeries constructed after differencing.

Return type

TimeSeries

drop_after(split_point: Union[pandas._libs.tslibs.timestamps.Timestamp, float, int])[source]

Drops everything after the provided timestamp ts, included. The timestamp may not be in the TimeSeries. If it is, the timestamp will be dropped.

Parameters

split_point – The timestamp that indicates cut-off time.

Returns

A new TimeSeries, after ts.

Return type

TimeSeries

drop_before(split_point: Union[pandas._libs.tslibs.timestamps.Timestamp, float, int])[source]

Drops everything before the provided timestamp ts, included. The timestamp may not be in the TimeSeries. If it is, the timestamp will be dropped.

Parameters

split_point – The timestamp that indicates cut-off time.

Returns

A new TimeSeries, after ts.

Return type

TimeSeries

property duration
returns: The duration of this time series; as a Timedelta if the series is indexed by a Datetimeindex,

and int otherwise.

Return type

Union[pandas.Timedelta, int]

end_time() → Union[pandas._libs.tslibs.timestamps.Timestamp, int][source]
Returns

A timestamp containing the last time of the TimeSeries (if indexed by DatetimeIndex), or an integer (if indexed by Int64Index/RangeIndex)

Return type

Union[pandas.Timestamp, int]

first_value() → float[source]
Returns

The first value of this univariate deterministic time series

Return type

float

first_values() → numpy.ndarray[source]
Returns

The first values of every component of this deterministic time series

Return type

np.ndarray

property freq
property freq_str
static from_csv(filepath_or_buffer: Union[PathLike[str], str, IO[T], io.RawIOBase, io.BufferedIOBase, io.TextIOBase, _io.TextIOWrapper, mmap.mmap], time_col: Optional[str] = None, value_cols: Optional[Union[List[str], str]] = None, fill_missing_dates: Optional[bool] = False, freq: Optional[str] = None, fillna_value: Optional[float] = None, **kwargs)TimeSeries[source]

Returns a deterministic TimeSeries instance built from a single CSV file. One column can be used to represent the time (if not present, the time index will be an Int64Index) and a list of columns value_cols can be used to indicate the values for this time series.

Parameters
  • filepath_or_buffer – The path to the CSV file, or the file object; consistent with the argument of pandas.read_csv function

  • time_col – The time column name. If set, the column will be cast to a pandas DatetimeIndex. If not set, the pandas Int64Index will be used.

  • value_cols – A string or list of strings representing the value column(s) to be extracted from the CSV file. If set to None, all columns from the CSV file will be used (except for the time_col, if specified)

  • fill_missing_dates – Optionally, a boolean value indicating whether to fill missing dates with NaN values. This requires either a provided freq or the possibility to infer the frequency from the provided timestamps. See _fill_missing_dates() for more info.

  • freq – Optionally, a string representing the frequency of the Pandas DateTimeIndex. This is useful in order to fill in missing values if some dates are missing and fill_missing_dates is set to True.

  • fillna_value – Optionally, a numeric value to fill missing values (NaNs) with.

  • **kwargs – Optional arguments to be passed to pandas.read_csv function

Returns

A univariate or multivariate deterministic TimeSeries constructed from the inputs.

Return type

TimeSeries

static from_dataframe(df: pandas.core.frame.DataFrame, time_col: Optional[str] = None, value_cols: Optional[Union[List[str], str]] = None, fill_missing_dates: Optional[bool] = False, freq: Optional[str] = None, fillna_value: Optional[float] = None)darts.timeseries.TimeSeries[source]

Returns a deterministic TimeSeries instance built from a selection of columns of a DataFrame. One column (or the DataFrame index) has to represent the time, and a list of columns value_cols has to represent the values for this time series.

Parameters
  • df – The DataFrame

  • time_col – The time column name. If set, the column will be cast to a pandas DatetimeIndex. If not set, the DataFrame index will be used. In this case the DataFrame must contain an index that is either a pandas DatetimeIndex or a pandas Int64Index (incl. RangeIndex). If a DatetimeIndex is used, it is better if it has no holes; alternatively setting fill_missing_dates can in some casees solve these issues (filling holes with NaN, or with the provided fillna_value numeric value, if any).

  • value_cols – A string or list of strings representing the value column(s) to be extracted from the DataFrame. If set to None, the whole DataFrame will be used.

  • fill_missing_dates – Optionally, a boolean value indicating whether to fill missing dates with NaN values. This requires either a provided freq or the possibility to infer the frequency from the provided timestamps. See _fill_missing_dates() for more info.

  • freq – Optionally, a string representing the frequency of the Pandas DateTimeIndex. This is useful in order to fill in missing values if some dates are missing and fill_missing_dates is set to True.

  • fillna_value – Optionally, a numeric value to fill missing values (NaNs) with.

Returns

A univariate or multivariate deterministic TimeSeries constructed from the inputs.

Return type

TimeSeries

static from_json(json_str: str)darts.timeseries.TimeSeries[source]

Converts the JSON String representation of a TimeSeries object (produced using TimeSeries.to_json()) into a TimeSeries object

At the moment this only supports deterministic time series (i.e., made of 1 sample).

Parameters

json_str – The JSON String to convert

Returns

The time series object converted from the JSON String

Return type

TimeSeries

static from_series(pd_series: pandas.core.series.Series, fill_missing_dates: Optional[bool] = False, freq: Optional[str] = None, fillna_value: Optional[float] = None)darts.timeseries.TimeSeries[source]

Returns a univariate and deterministic TimeSeries built from a pandas Series.

The series must contain an index that is either a pandas DatetimeIndex or a pandas Int64Index (incl. RangeIndex). If a DatetimeIndex is used, it is better if it has no holes; alternatively setting fill_missing_dates can in some cases solve these issues (filling holes with NaN, or with the provided fillna_value numeric value, if any).

Parameters
  • pd_series – The pandas Series instance.

  • fill_missing_dates – Optionally, a boolean value indicating whether to fill missing dates with NaN values. This requires either a provided freq or the possibility to infer the frequency from the provided timestamps. See _fill_missing_dates() for more info.

  • freq – Optionally, a string representing the frequency of the Pandas DateTimeIndex. This is useful in order to fill in missing values if some dates are missing and fill_missing_dates is set to True.

  • fillna_value – Optionally, a numeric value to fill missing values (NaNs) with.

Returns

A univariate and deterministic TimeSeries constructed from the inputs.

Return type

TimeSeries

static from_times_and_values(times: Union[pandas.core.indexes.datetimes.DatetimeIndex, pandas.core.indexes.numeric.Int64Index], values: numpy.ndarray, fill_missing_dates: Optional[bool] = False, freq: Optional[str] = None, columns: Optional[Collection] = None, fillna_value: Optional[float] = None)darts.timeseries.TimeSeries[source]

Returns a TimeSeries built from an index and value array.

Parameters
  • times – A pandas.DateTimeIndex or pandas.Int64Index (or pandas.RangeIndex) representing the time axis for the time series. If a DatetimeIndex is used, it is better if it has no holes; alternatively setting fill_missing_dates can in some cases solve these issues (filling holes with NaN, or with the provided fillna_value numeric value, if any).

  • values – A Numpy array of values for the TimeSeries. Both 2-dimensional arrays, for deterministic series, and 3-dimensional arrays, for probabilistic series, are accepted. In the former case the dimensions should be (time, component), and in the latter case (time, component, sample).

  • fill_missing_dates – Optionally, a boolean value indicating whether to fill missing dates with NaN values. This requires either a provided freq or the possibility to infer the frequency from the provided timestamps. See _fill_missing_dates() for more info.

  • freq – Optionally, a string representing the frequency of the Pandas DateTimeIndex. This is useful in order to fill in missing values if some dates are missing and fill_missing_dates is set to True.

  • columns – Columns to be used by the underlying pandas DataFrame.

  • fillna_value – Optionally, a numeric value to fill missing values (NaNs) with.

Returns

A TimeSeries constructed from the inputs.

Return type

TimeSeries

static from_values(values: numpy.ndarray, columns: Optional[Collection] = None, fillna_value: Optional[float] = None)darts.timeseries.TimeSeries[source]

Returns a TimeSeries built from an array of values. The series will have an integer index (Int64Index).

Parameters
  • values – A Numpy array of values for the TimeSeries. Both 2-dimensional arrays, for deterministic series, and 3-dimensional arrays, for probabilistic series, are accepted. In the former case the dimensions should be (time, component), and in the latter case (time, component, sample).

  • columns – Columns to be used by the underlying pandas DataFrame.

  • fillna_value – Optionally, a numeric value to fill missing values (NaNs) with.

Returns

A TimeSeries constructed from the inputs.

Return type

TimeSeries

static from_xarray(xa: xarray.core.dataarray.DataArray, fill_missing_dates: Optional[bool] = False, freq: Optional[str] = None, fillna_value: Optional[float] = None)darts.timeseries.TimeSeries[source]

Returns a TimeSeries instance built from an xarray DataArray. The dimensions of the DataArray have to be (time, component, sample), in this order. The time dimension can have an arbitrary name, but component and sample must be named “component” and “sample”, respectively.

The first dimension (time), and second dimension (component) must be indexed (i.e., have coordinates). The time must be indexed either with a pandas DatetimeIndex or a pandas Int64Index. If a DatetimeIndex is used, it is better if it has no holes; alternatively setting fill_missing_dates can in some cases solve these issues (filling holes with NaN, or with the provided fillna_value numeric value, if any).

If two components have the same name or are not strings, this method will disambiguate the components names by appending a suffix of the form “<name>_N” to the N-th column with name “name”.

Parameters
  • xa – The xarray DataArray

  • fill_missing_dates – Optionally, a boolean value indicating whether to fill missing dates with NaN values. This requires either a provided freq or the possibility to infer the frequency from the provided timestamps. See _fill_missing_dates() for more info.

  • freq – Optionally, a string representing the frequency of the Pandas DateTimeIndex. This is useful in order to fill in missing values if some dates are missing and fill_missing_dates is set to True.

  • fillna_value – Optionally, a numeric value to fill missing values (NaNs) with.

Returns

A univariate or multivariate deterministic TimeSeries constructed from the inputs.

Return type

TimeSeries

gaps() → pandas.core.frame.DataFrame[source]

A function to compute and return gaps in the TimeSeries. Works only on deterministic time series (1 sample).

Returns

A pandas.DataFrame containing a row for every gap (rows with all-NaN values in underlying DataFrame) in this time series. The DataFrame contains three columns that include the start and end time stamps of the gap and the integer length of the gap (in self.freq units if the series is indexed by a DatetimeIndex).

Return type

pd.DataFrame

get_index_at_point(point: Union[pandas._libs.tslibs.timestamps.Timestamp, float, int], after=True) → int[source]

Converts a point into an integer index

Parameters
  • point

    This parameter supports 3 different data types: pd.Timestamp, float and int.

    pd.Timestamp work only on series that are indexed with a pd.DatetimeIndex. In such cases, the returned point will be the index of this timestamp if it is present in the series time index. It it’s not present in the time index, the index of the next timestamp is returned if after=True (if it exists in the series), otherwise the index of the previous timestamp is returned (if it exists in the series).

    In case of a float, the parameter will be treated as the proportion of the time series that should lie before the point.

    In the case of int, the parameter will returned as such, provided that it is in the series. Otherwise it will raise a ValueError.

  • after – If the provided pandas Timestamp is not in the time series index, whether to return the index of the next timestamp or the index of the previous one.

get_timestamp_at_point(point: Union[pandas._libs.tslibs.timestamps.Timestamp, float, int]) → pandas._libs.tslibs.timestamps.Timestamp[source]

Converts a point into a pandas.Timestamp (if Datetime-indexed) or into an integer (if Int64-indexed).

Parameters

point – This parameter supports 3 different data types: float, int and pandas.Timestamp. In case of a float, the parameter will be treated as the proportion of the time series that should lie before the point. In the case of int, the parameter will be treated as an integer index to the time index of series. Will raise a ValueError if not a valid index in series In case of a pandas.Timestamp, point will be returned as is provided that the timestamp is present in the series time index, otherwise will raise a ValueError.

property has_datetime_index

Whether this series is indexed with a DatetimeIndex (otherwise it is indexed with an Int64Index)

property has_range_index

Whether this series is indexed with an Int64Index (otherwise it is indexed with a DatetimeIndex)

has_same_time_as(other: darts.timeseries.TimeSeries) → bool[source]

Checks whether this TimeSeries and another one have the same time index.

Parameters

other – the other series

Returns

True if both TimeSeries have the same index, False otherwise.

Return type

bool

property is_deterministic
property is_probabilistic
property is_stochastic
property is_univariate
is_within_range(ts: Union[pandas._libs.tslibs.timestamps.Timestamp, int]) → bool[source]

Check whether a given timestamp or integer is withing the time interval of this time series. If a timestamp is provided, it does not need to be an element of the time index of the series.

Parameters

ts – The pandas.Timestamp (if indexed with DatetimeIndex) or integer (if indexed with Int64Index) to check.

Returns

Whether ts is contained within the interval of this time series.

Return type

bool

kurtosis(axis=None, skipna=None, level=None, numeric_only=None, **kwargs) → float[source]
last_value() → float[source]
Returns

The last value of this univariate deterministic time series

Return type

float

last_values() → numpy.ndarray[source]
Returns

The last values of every component of this deterministic time series

Return type

np.ndarray

longest_contiguous_slice(max_gap_size: int = 0)darts.timeseries.TimeSeries[source]

Returns the largest TimeSeries slice of this deterministic time series that contains no gaps (contigouse all-NaN rows) larger than max_gap_size.

This method is only applicable to deterministic series (i.e., having 1 sample).

Returns

a new series constituting the largest slice of the original with no or bounded gaps

Return type

TimeSeries

map(fn: Union[Callable[[numpy.number], numpy.number], Callable[[Union[pandas._libs.tslibs.timestamps.Timestamp, int], numpy.number], numpy.number]])darts.timeseries.TimeSeries[source]

Applies the function fn elementwise to all values in this TimeSeries. Returns a new TimeSeries instance. If fn takes 1 argument it is simply applied elementwise. If it takes 2 arguments, it is applied elementwise on the (timestamp, value) tuples.

At the moment this function works only on deterministic time series (i.e., made of 1 sample).

Parameters

fn – Either a function which takes a value and returns a value ie. f(x) = y Or a function which takes a value and its timestamp and returns a value ie. f(timestamp, x) = y The type of timestamp is either pd.Timestamp (if the series is indexed with a DatetimeIndex), or an integer otherwise (if the series is indexed with an Int64Index).

Returns

A new TimeSeries instance

Return type

TimeSeries

max(axis=None, skipna=None, level=None, numeric_only=None, **kwargs) → float[source]
mean(axis=None, skipna=None, level=None, numeric_only=None, **kwargs) → float[source]
median(axis=None, skipna=None, level=None, numeric_only=None, **kwargs) → float[source]
min(axis=None, skipna=None, level=None, numeric_only=None, **kwargs) → float[source]
property n_components
property n_samples
property n_timesteps
pd_dataframe(copy=True) → pandas.core.frame.DataFrame[source]

Returns a Pandas DataFrame representation of this time series. Each of the series components will appear as a column in the DataFrame. Works only for deterministic series (i.e., made of 1 sample).

Parameters

copy – Whether to return a copy of the dataframe. Leave it to True unless you know what you are doing.

Returns

The Pandas DataFrame representation of this time series

Return type

pandas.DataFrame

pd_series(copy=True) → pandas.core.series.Series[source]

Returns a Pandas Series representation of this time series. Works only for univariate series that are deterministic (i.e., made of 1 sample).

Parameters

copy – Whether to return a copy of the series. Leave it to True unless you know what you are doing.

Returns

A Pandas Series representation of this univariate time series.

Return type

pandas.Series

plot(new_plot: bool = False, central_quantile: Union[float, str] = 0.5, low_quantile: Optional[float] = 0.05, high_quantile: Optional[float] = 0.95, *args, **kwargs)[source]

A wrapper method around xarray.DataArray.plot().

Parameters
  • new_plot – whether to spawn a new Figure

  • central_quantile – The quantile (between 0 and 1) to plot as a “central” value, if the series is stochastic (i.e., if it has multiple samples). This will be applied on each component separately (i.e., to display quantiles of the components’ marginal distributions). For instance, setting central_quantile=0.5 will plot the median of each component. central_quantile can also be set to ‘mean’.

  • low_quantile – The quantile to use for the lower bound of the plotted confidence interval. Similar to central_quantile, this is applied to each component separately (i.e., displaying marginal distributions). No confidence interval is shown if confidence_low_quantile is None (default 0.05).

  • high_quantile – The quantile to use for the upper bound of the plotted confidence interval. Similar to central_quantile, this is applied to each component separately (i.e., displaying marginal distributions). No confidence interval is shown if high_quantile is None (default 0.95).

  • args – some positional arguments for the plot() method

  • kwargs – some keyword arguments for the plot() method

quantile_df(quantile=0.5) → pandas.core.frame.DataFrame[source]

Returns a Pandas DataFrame containing the single desired quantile of each component (over the samples). Each of the series components will appear as a column in the DataFrame. The column will be named “<component>_X”, where “<component>” is the column name corresponding to this component, and “X” is the quantile value. The quantile columns represent the marginal distributions of the components of this series.

This works only on stochastic series (i.e., with more than 1 sample)

Parameters

quantile – The desired quantile value. The value must be represented as a fraction (between 0 and 1 inclusive). For instance, 0.5 will return a DataFrame containing the median of the (marginal) distribution of each component.

Returns

The Pandas DataFrame containing the desired quantile for each component.

Return type

pandas.DataFrame

quantile_timeseries(quantile=0.5)darts.timeseries.TimeSeries[source]

Returns a deterministic TimeSeries containing the single desired quantile of each component (over the samples) of this stochastic TimeSeries. The components in the new series are named “<component>_X”, where “<component>” is the column name corresponding to this component, and “X” is the quantile value. The quantile columns represent the marginal distributions of the components of this series.

This works only on stochastic series (i.e., with more than 1 sample)

Parameters

quantile – The desired quantile value. The value must be represented as a fraction (between 0 and 1 inclusive). For instance, 0.5 will return a TimeSeries containing the median of the (marginal) distribution of each component.

Returns

The TimeSeries containing the desired quantile for each component.

Return type

TimeSeries

quantiles_df(quantiles: Tuple[float] = 0.1, 0.5, 0.9) → pandas.core.frame.DataFrame[source]

Returns a Pandas DataFrame containing the desired quantiles of each component (over the samples). Each of the series components will appear as a column in the DataFrame. The column will be named “<component>_X”, where “<component>” is the column name corresponding to this component, and “X” is the quantile value. The quantiles represent the marginal distributions of the components of this series.

This works only on stochastic series (i.e., with more than 1 sample)

Parameters

quantiles – Tuple containing the desired quantiles. The values must be represented as fractions (between 0 and 1 inclusive). For instance, (0.1, 0.5, 0.9) will return a DataFrame containing the 10th-percentile, median and 90th-percentile of the (marginal) distribution of each component.

Returns

The Pandas DataFrame containing the quantiles for each component.

Return type

pandas.DataFrame

resample(freq: str, method: str = 'pad')darts.timeseries.TimeSeries[source]

Creates an reindexed time series with a given frequency. Provided method is used to fill holes in reindexed TimeSeries, by default ‘pad’.

Parameters
  • freq – The new time difference between two adjacent entries in the returned TimeSeries. A DateOffset alias is expected.

  • method

    Method to fill holes in reindexed TimeSeries (note this does not fill NaNs that already were present):

    ‘pad’: propagate last valid observation forward to next valid

    ‘backfill’: use NEXT valid observation to fill.

Returns

A reindexed TimeSeries with given frequency.

Return type

TimeSeries

rescale_with_value(value_at_first_step: float)darts.timeseries.TimeSeries[source]

Returns a new TimeSeries, which is a multiple of this TimeSeries such that the first value is value_at_first_step. (Note: numerical errors can appear with value_at_first_step > 1e+24).

Parameters

value_at_first_step – The new value for the first entry of the TimeSeries.

Returns

A new TimeSeries, where the first value is value_at_first_step and other values have been scaled accordingly.

Return type

TimeSeries

shift(n: int)darts.timeseries.TimeSeries[source]

Shifts the time axis of this TimeSeries by n time steps.

If \(n > 0\), shifts in the future. If \(n < 0\), shifts in the past.

For example, with \(n=2\) and freq=’M’, March 2013 becomes May 2013. With \(n=-2\), March 2013 becomes Jan 2013.

Parameters

n – The number of time steps (in self.freq unit) to shift by. Can be negative.

Returns

A new TimeSeries, with a shifted index.

Return type

TimeSeries

skew(axis=None, skipna=None, level=None, numeric_only=None, **kwargs) → float[source]
slice(start_ts: Union[pandas._libs.tslibs.timestamps.Timestamp, int], end_ts: Union[pandas._libs.tslibs.timestamps.Timestamp, int])[source]

Returns a new TimeSeries, starting later than start_ts and ending before end_ts, inclusive on both ends. The timestamps don’t have to be in the series.

Parameters
  • start_ts – The timestamp that indicates the left cut-off.

  • end_ts – The timestamp that indicates the right cut-off.

Returns

A new series, with indices greater or equal than start_ts and smaller or equal than end_ts.

Return type

TimeSeries

slice_intersect(other: darts.timeseries.TimeSeries)darts.timeseries.TimeSeries[source]

Returns a TimeSeries slice of this time series, where the time index has been intersected with the one provided in argument. Note that this method is in general not symmetric.

Parameters

other – the other time series

Returns

a new series, containing the values of this series, over the time-span common to both time series.

Return type

TimeSeries

slice_n_points_after(start_ts: Union[pandas._libs.tslibs.timestamps.Timestamp, int], n: int)darts.timeseries.TimeSeries[source]

Returns a new TimeSeries, starting a start_ts and having at most n points.

The provided timestamps will be included in the series.

Parameters
  • start_ts – The timestamp or index that indicates the splitting time.

  • n – The maximal length of the new TimeSeries.

Returns

A new TimeSeries, with length at most n, starting at start_ts

Return type

TimeSeries

slice_n_points_before(end_ts: Union[pandas._libs.tslibs.timestamps.Timestamp, int], n: int)darts.timeseries.TimeSeries[source]

Returns a new TimeSeries, ending at start_ts and having at most n points.

The provided timestamps will be included in the series.

Parameters
  • end_ts – The timestamp or index that indicates the splitting time.

  • n – The maximal length of the new TimeSeries.

Returns

A new TimeSeries, with length at most n, ending at start_ts

Return type

TimeSeries

split_after(split_point: Union[pandas._libs.tslibs.timestamps.Timestamp, float, int]) → Tuple[darts.timeseries.TimeSeries, darts.timeseries.TimeSeries][source]

Splits the TimeSeries in two, after a provided split_point.

Parameters

split_point – A timestamp, float or integer. If float, represents the proportion of the series to include in the first TimeSeries (must be between 0.0 and 1.0). If integer, represents the index position after which the split is performed. A pd.Timestamp can be provided for TimeSeries that are indexed by a pd.DatetimeIndex. In such cases, the timestamp will be contained in the first TimeSeries, but not in the second one. The timestamp itself does not have to appear in the original TimeSeries index.

Returns

A tuple of two time series. The first time series contains the first samples up to the split_point, and the second contains the remaining ones.

Return type

Tuple[TimeSeries, TimeSeries]

split_before(split_point: Union[pandas._libs.tslibs.timestamps.Timestamp, float, int]) → Tuple[darts.timeseries.TimeSeries, darts.timeseries.TimeSeries][source]

Splits the TimeSeries in two, before a provided split_point.

Parameters

split_point – A timestamp, float or integer. If float, represents the proportion of the series to include in the first TimeSeries (must be between 0.0 and 1.0). If integer, represents the index position before which the split is performed. A pd.Timestamp can be provided for TimeSeries that are indexed by a pd.DatetimeIndex. In such cases, the timestamp will be contained in the second TimeSeries, but not in the first one. The timestamp itself does not have to appear in the original TimeSeries index.

Returns

A tuple of two time series. The first time series contains the first samples up to the split_point, and the second contains the remaining ones.

Return type

Tuple[TimeSeries, TimeSeries]

stack(other: darts.timeseries.TimeSeries)darts.timeseries.TimeSeries[source]

Stacks another univariate or multivariate TimeSeries with the same time index on top of the current one (along the component axis), and returns the newly formed multivariate TimeSeries that includes all the components of self and of other.

The resulting TimeSeries will have the same name for its time dimension as this TimeSeries, and the same number of samples.

Parameters

other – A TimeSeries instance with the same index and the same number of samples as the current one.

Returns

A new multivariate TimeSeries instance.

Return type

TimeSeries

start_time() → Union[pandas._libs.tslibs.timestamps.Timestamp, int][source]
Returns

A timestamp containing the first time of the TimeSeries (if indexed by DatetimeIndex), or an integer (if indexed by Int64Index/RangeIndex)

Return type

Union[pandas.Timestamp, int]

std(axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs) → float[source]
strip()darts.timeseries.TimeSeries[source]

Returns a TimeSeries slice of this deterministic time series, where NaN-only entries at the beginning and the end of the series are removed. No entries after (and including) the first non-NaN entry and before (and including) the last non-NaN entry are removed.

This method is only applicable to deterministic series (i.e., having 1 sample).

Returns

a new series based on the original where NaN-only entries at start and end have been removed

Return type

TimeSeries

sum(axis=None, skipna=None, level=None, numeric_only=None, min_count=0, **kwargs) → float[source]
property time_index

returns: The time index of this time series. :rtype: Union[pd.DatetimeIndex, pd.Int64Index]

to_json() → str[source]

Converts the TimeSeries object to a JSON String

At the moment this function works only on deterministic time series (i.e., made of 1 sample).

Returns

A JSON String representing the time series

Return type

str

univariate_component(index: Union[str, int])darts.timeseries.TimeSeries[source]

Retrieves one of the components of the current TimeSeries instance and returns it as new univariate TimeSeries instance.

Parameters

index – An zero-indexed integer indicating which component to retrieve. If components have names, this can be a string with the component’s name.

Returns

A new univariate TimeSeries instance.

Return type

TimeSeries

univariate_values(copy=True, sample=0) → numpy.ndarray[source]

Returns a 1-D Numpy array of dimension (time,), containing this univariate series’ values for one sample. If this series is deterministic, it contains only one sample and only sample=0 can be used.

Parameters

copy – Whether to return a copy of the values. Leave it to True unless you know what you are doing.

Returns

The values composing the time series guaranteed to be univariate.

Return type

numpy.ndarray

values(copy=True, sample=0) → numpy.ndarray[source]

Returns a 2-D Numpy array of dimension (time, component), containing this series’ values for one sample. If this series is deterministic, it contains only one sample and only sample=0 can be used.

Parameters
  • copy – Whether to return a copy of the values, otherwise returns a view. Leave it to True unless you know what you are doing.

  • sample – For stochastic series, the sample for which to return values. Default: 0 (first sample).

Returns

The values composing the time series.

Return type

numpy.ndarray

var(axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs) → float[source]
property width
with_columns_renamed(col_names: Union[List[str], str], col_names_new: Union[List[str], str])darts.timeseries.TimeSeries[source]

Changes ts column names and returns a new TimeSeries instance.

Parameters
  • col_names – String or list of strings corresponding the the column names to be changed.

  • col_names_new – String or list of strings corresponding to the new column names. Must be the same length as col_names.

Returns

A new TimeSeries instance.

Return type

TimeSeries