tspy.data_structures.time_series.SegmentTimeSeries module¶
-
class
tspy.data_structures.time_series.SegmentTimeSeries.
SegmentTimeSeries
(tsc, j_ts, trs=None)¶ Bases:
tspy.data_structures.time_series.TimeSeries.TimeSeries
A special form of time-series that consists of observations with a value of type
Segment
- Attributes
trs
Returns
Methods
cache
([cache_size])suggest to the time-series to cache values
collect
([inclusive])collect all observations in this time-series
concat
(other_time_series)produce a new time-series which is the result of concatenating two time-series
count
([inclusive])count the current number of observations in this time-series
describe
()retrieve time-series statistics computed from all values in this time-series
fillna
(interpolator[, null_value])produce a new time-series which is the result of filling all null values.
filter
(func)produce a new time-series which is the result of filtering by each observation’s value given a filter function.
flatmap
(func)produce a new time-series where each observation’s value in this time-series is mapped to 0 to N new values.
flatten
([key_func])converts this segment-time-series into a multi-time-series where each time-series will be the result of a single segment
forecast
(num_predictions, fm[, …])forecast the next num_predictions using a forecasting model
full_align
(time_series[, left_interp_func, …])align two time-series based on a temporal full join strategy and optionally interpolate missing values
full_join
(time_series[, join_func, …])join two time-series based on a temporal full join strategy and optionally interpolate missing values
get_values
(start, end[, inclusive])get all values between a range in this time-series
inner_align
(time_series)align two time-series based on a temporal inner join strategy
inner_join
(time_series[, join_func])join two time-series based on a temporal inner join strategy
lag
(lag_amount)produce a new time-series which is a lagged version of the current time-series.
left_align
(time_series[, interp_func])align two time-series based on a temporal left join strategy and optionally interpolate missing values
left_join
(time_series[, join_func, interp_func])join two time-series based on a temporal left join strategy and optionally interpolate missing values
left_outer_align
(time_series[, interp_func])align two time-series based on a temporal left outer join strategy and optionally interpolate missing values
left_outer_join
(time_series[, join_func, …])join two time-series based on a temporal left outer join strategy and optionally interpolate missing values
map
(func)produce a new time-series where each observation’s value in this time-series is mapped to a new observation value
map_with_index
(func)produce a new time-series where each observation’s value in this time-series is mapped given the old value and an index to a new observation value
print
([start, end, inclusive, human_readable])print this time-series
reduce
(*args)reduce this time-series or two time-series to a single value
resample
(period, func)produce a new time-series by resampling the current time-series to a given periodicity
right_align
(time_series[, interp_func])align two time-series based on a temporal right join strategy and optionally interpolate missing values
right_join
(time_series[, join_func, interp_func])join two time-series based on a temporal right join strategy and optionally interpolate missing values
right_outer_align
(time_series[, interp_func])align two time-series based on a temporal right outer join strategy and optionally interpolate missing values
right_outer_join
(time_series[, join_func, …])join two time-series based on a temporal right outer join strategy and optionally interpolate missing values
segment
(window[, step, enforce_size])produce a new segment-time-series from a performing a sliding-based segmentation over the time-series
segment_by
(func)produce a new segment-time-series from a performing a group-by operation on each observation’s value
segment_by_anchor
(func, left_delta, right_delta)produce a new segment-time-series from performing an anchor-based segmentation over the time-series.
segment_by_changepoint
([change_point])produce a new segment-time-series from performing a chang-point based segmentation.
segment_by_marker
(*args, **kwargs)produce a new segment-time-series from performing a marker based segmentation.
segment_by_time
(window, step)produce a new segment-time-series from a performing a time-based segmentation over the time-series
shift
(shift_amount[, default_value])produce a new time-series which is a shifted version of the current time-series.
to_df
([inclusive])convert this time-series to a pandas dataframe
to_segments
(segment_transform)produce a new segment-time-series from a segmentation transform
transform
(*args)produce a new time-series which is the result of performing a transforming over the time-series.
uncache
()remove the time-series caching mechanism
with_trs
([granularity, start_time])create a new time-series with its timestamps mapped based on a granularity and start_time.
write
([start, end, inclusive])create a time-series-writer given a range
-
cache
(cache_size=None)¶ suggest to the time-series to cache values
- Parameters
- cache_sizeint, optional
the max cache size (default is max long)
- Returns
TimeSeries
a new time-series
Notes
this is a lazy operation and will only suggest to the time-series to save values once computed
-
flatmap
(func)¶ produce a new time-series where each observation’s value in this time-series is mapped to 0 to N new values.
- Parameters
- funcfunc
value mapping function which returns a list of values
- Returns
TimeSeries
a new time-series with its values flat-mapped
Notes
an observations time-tick will be duplicated if a single value maps to multiple values
Examples
create a simple time-series
>>> import tspy >>> ts_orig = tspy.time_series([1, 2, 3]) >>> ts_orig TimeStamp: 0 Value: 1 TimeStamp: 1 Value: 2 TimeStamp: 2 Value: 3
flat map each time-series observation value by duplicating the value
>>> ts = ts_orig.flatmap(lambda x: [x, x]) >>> ts TimeStamp: 0 Value: 1 TimeStamp: 0 Value: 1 TimeStamp: 1 Value: 2 TimeStamp: 1 Value: 2 TimeStamp: 2 Value: 3 TimeStamp: 2 Value: 3
-
flatten
(key_func=None)¶ converts this segment-time-series into a multi-time-series where each time-series will be the result of a single segment
- Parameters
- key_funcfunc, optional
operation where given a segment, produce a unique key (default is create key based on start of segment)
- Returns
MultiTimeSeries
a new multi-time-series
Notes
this is not a lazy operation and will materialize the time-series
Examples
create a simple time-series
>>> import tspy >>> ts_orig = tspy.data_structures.list([1,2,3,4,5,6]) >>> ts_orig TimeStamp: 0 Value: 1 TimeStamp: 1 Value: 2 TimeStamp: 2 Value: 3 TimeStamp: 3 Value: 4 TimeStamp: 4 Value: 5 TimeStamp: 5 Value: 6
segment the time-series using a simple sliding window
>>> ts_sliding = ts_orig.segment(2) >>> ts_sliding TimeStamp: 0 Value: original bounds: (0,1) actual bounds: (0,1) observations: [(0,1),(1,2)] TimeStamp: 1 Value: original bounds: (1,2) actual bounds: (1,2) observations: [(1,2),(2,3)] TimeStamp: 2 Value: original bounds: (2,3) actual bounds: (2,3) observations: [(2,3),(3,4)] TimeStamp: 3 Value: original bounds: (3,4) actual bounds: (3,4) observations: [(3,4),(4,5)] TimeStamp: 4 Value: original bounds: (4,5) actual bounds: (4,5) observations: [(4,5),(5,6)]
flatten the segments into a single multi-time-series
>>> mts = ts_sliding.flatten() >>> mts 0 time series ------------------------------ TimeStamp: 0 Value: 1 TimeStamp: 1 Value: 2 1 time series ------------------------------ TimeStamp: 1 Value: 2 TimeStamp: 2 Value: 3 2 time series ------------------------------ TimeStamp: 2 Value: 3 TimeStamp: 3 Value: 4 3 time series ------------------------------ TimeStamp: 3 Value: 4 TimeStamp: 4 Value: 5 4 time series ------------------------------ TimeStamp: 4 Value: 5 TimeStamp: 5 Value: 6
-
map
(func)¶ produce a new time-series where each observation’s value in this time-series is mapped to a new observation value
- Parameters
- funcfunc
value mapping function
- Returns
TimeSeries
a new time-series with its values re-mapped
Examples
create a simple time-series
>>> import tspy >>> ts_orig = tspy.time_series([1, 2, 3]) >>> ts_orig TimeStamp: 0 Value: 1 TimeStamp: 1 Value: 2 TimeStamp: 2 Value: 3
add one to each value of the time-series and produce a new time-series
>>> ts = ts_orig.map(lambda x: x + 1) >>> ts TimeStamp: 0 Value: 2 TimeStamp: 1 Value: 3 TimeStamp: 2 Value: 4
map each value of the time-series to a string and produce a new time-series
>>> ts = ts_orig.map(lambda x: "value - " + str(x)) >>> ts TimeStamp: 0 Value: value - 1 TimeStamp: 1 Value: value - 2 TimeStamp: 2 Value: value - 3
map each value of the time-series to a string using high performant expressions
>>> from tspy.functions import expressions as exp >>> ts = ts_orig.map(exp.add(exp.id(), 1)) TimeStamp: 0 Value: 2.0 TimeStamp: 1 Value: 3.0 TimeStamp: 2 Value: 4.0