Operators
The operators are a set of interfaces describing an operation that can be applied over a number of potential inputs types.
Where possible the operators are mapped onto Python symbolic operators (for example +, -, /, etc.).
When describing an operator that clashes with a builtin operator name such as add we add an _ to the end of
the name. In this case it would be add_.
See this for a quick guide of supported types and operators Operators Support.
These are the operators that are provided by the HGraph library.
- abs_(ts: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the
absoperator for time series types.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- add_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE_1) OUT[source]
This represents the
+operator for time series types.- Return type:
Default
- apply(fn: TS[Callable], args: TSB[TS_SCHEMA], kwargs: TSB[TS_SCHEMA_1]) TIME_SERIES_TYPE
Apply the inputs to the fn provided. This allows a function to be passed as a time-series value, and it will be used to evaluate the inputs as they tick. This will not allow the function to be called unless are args are valid, but this is not required for kwargs.
- batch(condition: TS[bool], ts: TS[SCALAR], delay: timedelta, buffer_length: int) TS[tuple[SCALAR, ...]][source]
Queues up ticks of a time series when the value of
conditionifFalse. Once it turns True the queued up ticks are released in batches with a given delay between each batch. ARuntimeErroris raised if the buffer exceeds the given buffer_length.- Return type:
TimeSeriesValueInput[Tuple[TypeVar(SCALAR, bound=object),...]]
- bit_and(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) OUT[source]
This represents the
&operator for time series types.- Return type:
Default
- bit_or(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[TIME_SERIES_TYPE_1][source]
This represents the
|operator for time series types.- Return type:
TimeSeriesValueInput[TypeVar(TIME_SERIES_TYPE_1, bound=TimeSeries)]
- bit_xor(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) OUT[source]
This represents the
^operator for time series types.- Return type:
Default
- cast_(tp: type[SCALAR], ts: TS[SCALAR_1]) TS[SCALAR][source]
Casts a time-series to a different type.
- Return type:
TimeSeriesValueInput[TypeVar(SCALAR, bound=object)]
- call(fn: TS[Callable], args: TSB[TS_SCHEMA], kwargs: TSB[TS_SCHEMA_1])[source]
Apply the inputs to the fn provided. This allows a function to be passed as a time-series value, and it will be used to evaluate the inputs as they tick. This will not allow the function to be called unless are args are valid, but this is not required for kwargs.
- clip(ts: OUT, min_: NUMBER, max_: NUMBER) OUT[source]
Clips the input value/s to be within the range provided. This can operate on a time-series of NUMBER or more complex data structures such as a data frame.
- Return type:
TypeVar(OUT, bound=TimeSeries)
- cmp_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[CmpResult][source]
Return one of LT, EQ, GT as a comparison result. This could be more efficient than performing a sequence of operations.
- Return type:
- combine(args: TIME_SERIES_TYPE) OUT[source]
Combines the incoming time series into one collection time-series output.
- Return type:
Default
- const(value: SCALAR, tp: type[OUT], delay: timedelta) OUT[source]
Produces a single tick at the start of the graph evaluation after which this node does nothing.
- Parameters:
value (
TypeVar(SCALAR, bound=object)) – The value in appropriate form to be applied to the time-series type specified in tp.tp (
type[TypeVar(OUT, bound=TimeSeries)]) – Used to resolve the correct type for the output, by default this is TS[SCALAR] where SCALAR is the type of the value.delay (
timedelta) – The amount of time to delay the value by. The default is 0.
- Return type:
Default- Returns:
A single tick of the value supplied.
- contains_(ts: TIME_SERIES_TYPE, item: TS[SCALAR]) TS[bool][source]
This represents the in operator for time series types, however, since
__contains__always returns a bool value, we can’t overload the__contains__, so it is not possible to doitem in ts, instead usecontains_(ts, item).This is logically:
item in ts- Return type:
- convert(ts: TIME_SERIES_TYPE, to: type[OUT]) OUT[source]
- Return type:
TypeVar(OUT, bound=TimeSeries)
Converts the incoming time series to the desired result type. This can be called in one of two ways:
c = const(..., TS[set[str]]) convert(c, TS[tuple[str, ...]])
or:
convert[TS[tuple[str, ...]]](c)
- collapse_keys(ts: TIME_SERIES_TYPE) OUT[source]
Given a nested TSD[K, TSD[K1, V]] collapse_keys will produce TSD[Tuple[K, K1], V] where the keys are pairs of outer and inner key for each value
- Return type:
TypeVar(OUT, bound=TimeSeries)
- collect(ts: TIME_SERIES_TYPE) OUT[source]
Converts the ts value to a collection time-series. The time-series to convert to must be provided declaratively. This is done by setting the OUT to the desired result type, for example:
ts = const(1) r = collect[OUT: TS[tuple[int, ...]](ts)
Where here we set the resultant type to be a time-series of tuples, the input would be a time-series of integers.
For processing a result type of dict or TSD the input must consist of a time-series of two time-series values where one represents the keys and the other represent the values.
For example:
ts = const(frozendict({"a": 1, "b": 2}), TSB[ts_schema(key=TS[str], value=TS[int])]) r = collect[OUT: TS[Mapping[str, int]](ts)
Alternative syntax includes:
key = const("a") value = const(1) r = collect[OUT: TS[Mapping[str, int]](key=key, value=value)
Or options such as the input being a
TSL[TS[SCALAR], Size[2]](in this case the key and value must be the same). It is also possible to accept a TS[Mapping[str, int]] or a TS[tuple[str, int]]- Return type:
Default
- count(ts: SIGNAL, reset: SIGNAL) TS[int][source]
Performs a running count of the number of times the time-series has ticked (i.e. emitted a value).
- Return type:
- default(ts: OUT, default_value: OUT) OUT[source]
Returns the time-series ts with any missing values replaced with default_value.
ts = … out = default(ts, 0) # Note the ability to pass in a constant value.
ts: TS[int] = … ts_default: TS[int] = … out = default(ts, ts_default)
- Parameters:
ts (
Default) – The time-series to replace missing values in.default_value (
TypeVar(OUT, bound=TimeSeries)) – The value to replace missing values with.
- Return type:
TypeVar(OUT, bound=TimeSeries)- Returns:
The time-series with missing values replaced with default_value.
- class DebugContext(prefix: str = '', debug: bool = True)[source]
A mechanism to support leaving useful debug code in place but will occur no runtime cost if the debug logic is not requested. This will only wire in the logic when the debug flag is set to True. By default, it is set to False.
An additional prefix can be supplied to the context, this will be pre-pended to all debug prints to provide additional context.
- debug_print(label: str, ts: TIME_SERIES_TYPE, print_delta: bool, sample: int)[source]
Use this to help debug code, this will print the value of the supplied time-series to the standard out. It will include the engine time in the print. Do not leave these lines in production code.
- Parameters:
label (
str) – The label to print before the valuets (
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)) – The time-series to printprint_delta (
bool) – If true, print the delta value, otherwise print the valuesample (
int) – Only print an output for every sample number of ticks.
- dedup(ts: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
Drops duplicate values from a time-series.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- diff(ts: OUT) OUT[source]
Computes the difference between the current value and the previous value in the time-series.
- Return type:
TypeVar(OUT, bound=TimeSeries)
- difference(tsl: TSL[TIME_SERIES_TYPE, SIZE]) OUT[source]
Performs a difference of the provided time-series values.
Difference is { p | p element of lhs and p not element of rhs }
- Return type:
Default
- div_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) OUT[source]
This represents the / operator for time series types.
Parameters: * divide_by_zero: DivideByZero - controls the behaviour when dividing by zero
- Return type:
Default
- divmod_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TSL[TIME_SERIES_TYPE, Size_2][source]
This represents the divmod operator for time series types. (This is defined in Python as the integer division with remainder, i.e. divmod(9, 4) == (2, 1))
- Return type:
TimeSeriesListInput[TypeVar(TIME_SERIES_TYPE, bound=TimeSeries),Size_2]
- downcast_(tp: type[SCALAR], ts: TS[SCALAR_1]) TS[SCALAR][source]
Downcasts a time-series to the given type.
- Return type:
TimeSeriesValueInput[TypeVar(SCALAR, bound=object)]
- downcast_ref(tp: type[SCALAR], ts: REF[TS[SCALAR_1]]) REF[TS[SCALAR]][source]
Downcasts a time-series reference to the given type. This is fast but unsafe as there is no type checking happens here
- Return type:
TimeSeriesReferenceInput[TimeSeriesValueInput[TypeVar(SCALAR, bound=object)]]
- drop(ts: TIME_SERIES_TYPE, count: INT_OR_TIME_DELTA) TIME_SERIES_TYPE[source]
Drops the first count ticks and then returns the remainder of the ticks
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- emit(ts: TIME_SERIES_TYPE) OUT[source]
Accepts a collection representation, for example:
TS[tuple[int, ...]]and returns a time-series of the values as a stream of individual ticks (in the example above that would beTS[int].- Return type:
Default
- eq_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[bool][source]
This represents the
==operator for time series types.- Return type:
- evaluation_time_in_range(start_time: TS[TIME_TYPE], end_time: TS[TIME_TYPE]) TS[CmpResult][source]
Indicates if the current evaluation time is less that, within, or greater than the time range provided.
It is possible to provide a pair to datetime values, or time, or dates.
In the case of datetime and date ranges, this is a precise comparison. In the case of times, the comparison will vary depending on the time ordering. A time that is within a day (when start_time < end_time) then it is greater than after the last time of the current date (in UTC) otherwise it is less than. When end < start, then the comparison will also be either before or in the range.
- Parameters:
start_time (
TimeSeriesValueInput[TypeVar(TIME_TYPE,datetime,date,time)]) – [datetime, date, time] The start time of the range.end_time (
TimeSeriesValueInput[TypeVar(TIME_TYPE,datetime,date,time)]) – [datetime, date, time] The end time of the range.
- Return type:
- Returns:
CmpResult indicating if the engine time is less than, within, or greater than the time range.
- explode(ts: TS[date]) TSL[TS[int], Size_3][source]
The year, month and day of the given date.
- Return type:
TimeSeriesListInput[TimeSeriesValueInput[int],Size_3]
- filter_(condition: TS[bool], ts: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
Suppresses ticks of a time series when the condition time series’ value is False
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- flip(ts: TIME_SERIES_TYPE) OUT[source]
Flips the dictionary so that the values become the keys and the keys become the values. Params: * unique: bool - if False, collects multiple keys into a TSS output instead of a single TS
- Return type:
Default
- flip_keys(ts: TIME_SERIES_TYPE) OUT[source]
Work on nested TSDs like TSD[K, TSD[K1, V]] to inverse keys to get TSD[K1, TSD[K, V]]
- Return type:
TypeVar(OUT, bound=TimeSeries)
- floordiv_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the // operator for time series types.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- format_(fmt: TS[str]) TS[str][source]
Writes the contents of the time-series values provided (in args / kwargs) to a string using the format string provided. The kwargs will be used as named inputs to the format string and args as enumerated args. :type fmt:
TimeSeriesValueInput[str] :param fmt: A standard python format string (using {}). When converted to C++ this will use the c++ fmtspecifications.
- Parameters:
__sample__ – set this to a positive value > 1 to only output every nth formatted string.
args – Time series args
kwargs – Time series kwargs
- Return type:
- Returns:
The formatted string.
- from_json(ts: TS[str]) OUT[source]
Converts the
tsJSON string to the OUT type. Usage would be along the lines of:value = from_json[TS[MySchema]](ts)
- Return type:
Default
- gate(condition: TS[bool], ts: TIME_SERIES_TYPE, buffer_length: int) TIME_SERIES_TYPE[source]
Queues up ticks of a time series when the value of
conditionisFalse. Once it turns True the queued-up ticks are released one by one. The default buffer length is sys.maxsize (which is roughly the same as unbounded). ARuntimeErroris raised if the buffer exceeds the given buffer_length (when set to a positive value). Setting the length to -1 will put the gate in last tick mode. In this mode the values are overwritten whilst the process is gating, once it has finished gating, the last modified value is released, and then ticks are processed as usual.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- ge_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[bool][source]
This represents the
>=operator for time series types.- Return type:
- getattr_(ts: TIME_SERIES_TYPE, attr: str, default_value: SCALAR) TIME_SERIES_TYPE_1[source]
This represents the
.operator for time-series types.Use this as:
ts.attror more explicitly:getattr_(ts, attr)- Return type:
TypeVar(TIME_SERIES_TYPE_1, bound=TimeSeries)
- getitem_(ts: TIME_SERIES_TYPE, key: TS[SCALAR]) TIME_SERIES_TYPE_1[source]
This represents the
[]operator for time-series types.Use this as:
ts[key]- Return type:
TypeVar(TIME_SERIES_TYPE_1, bound=TimeSeries)
- gt_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[bool][source]
This represents the
>operator for time series types.- Return type:
- if_(condition: TS[bool], ts: TIME_SERIES_TYPE) TSB[BoolResult][source]
Forwards a timeseries value to one of two bundle outputs: “true” or “false”, according to whether the condition is true or false
- Return type:
- if_cmp(cmp: TS[CmpResult], lt: OUT, eq: OUT, gt: OUT) OUT[source]
Performs a comparison between two time series values (
lhsandrhs), then depending on the result will select the time-series of interest. That is:if lhs < rhs: return lt if lhs == rhs: return eq if lhs > rhs: return gt
- Return type:
TypeVar(OUT, bound=TimeSeries)
- if_then_else(condition: TS[bool], true_value: TIME_SERIES_TYPE, false_value: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
If the condition is true the output ticks with the true_value, otherwise it ticks with the false_value.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- if_true(condition: TS[bool], tick_once_only: bool) TS[bool][source]
Emits a tick with value True when the input condition ticks with True. If tick_once_only is True then this will only tick once, otherwise this will tick with every tick of the condition, when the condition is True.
- Return type:
- index_of(ts: TIME_SERIES_TYPE_1, item: TIME_SERIES_TYPE_2) TS[int][source]
Returns the index of a value within the ts provided. Options include:
- Return type:
- TS[tuple[SCALAR, …]]
returns the index of the first occurrence of the item in the tuple
- TSL[TIME_SERIES_TYPE_2, SIZE]
returns the index of the first occurrence of the item in the TSL
- intersection(tsl: TSL[TIME_SERIES_TYPE, SIZE]) OUT[source]
Performs an intersection of the provided time-series values.
Intersection is { p | p in all tsl[i] for i in range(len(tsl)) }
- Return type:
Default
- invert_(ts: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the unary
~operator for time series types.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- is_empty(ts: TIME_SERIES_TYPE) TS[bool][source]
Returns True if the value of the time-series is considered empty, False otherwise.
- Return type:
- join(strings: TSL[TS[str], SIZE], separator: str) TS[str][source]
Joins the strings with the separator.
- Return type:
- keys_(ts: TIME_SERIES_TYPE) OUT[source]
Returns the TSS or set of keys in a dictionary.
- Return type:
Default
- lag(ts: TIME_SERIES_TYPE, period: INT_OR_TIME_DELTA, on_wall_clock: bool) TIME_SERIES_TYPE[source]
Delays the delivery of an input by the period specified. This period can either be a number of ticks or a time-delta. In the case of a timedelta, on_wall_clock determines if the schedule is on the wall clock or on engine time
When a time-delta is specified the value will be scheduled to be delivered at the receipt time + period.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- last_modified_date(ts: SIGNAL) TS[date][source]
The date component of the last modified time of the time series.
- Return type:
- last_modified_time(ts: SIGNAL) TS[datetime][source]
The datetime representing the last modified time of the time series.
- Return type:
- le_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[bool][source]
This represents the
<=operator for time series types.- Return type:
- len_(ts: TIME_SERIES_TYPE) TS[int][source]
This represents the len operator for time series types.
- Return type:
- lift(fn: Callable, inputs: dict[str, type[TimeSeries]] = None, output: type[TimeSeries] = None, active: Sequence[str] | Callable = None, valid: Sequence[str] | Callable = None, all_valid: Sequence[str] | Callable = None, dedup_output: bool = False, defaults: dict[str, Any] = None)[source]
Wraps a scalar function producing a time-series version of the function.
By default, and assuming the function is appropriately annotated, the function will be wrapped into a
compute_node, with the args each wrapped with TS[<type>] and the result wrapped with TS[<type>].If different time-series types are required, then supply the overrides as appropriate.
- log_(format_str: TS[str], args: TSB[TS_SCHEMA], level: int, sample_count: int, kwargs: TSB[TS_SCHEMA_1])[source]
A sink node that will log the formatted string to the system logger.
- Parameters:
format_str (
TimeSeriesValueInput[str]) – The format string as defined in formatlevel (
int) – The logging levelargs (
TimeSeriesBundleInput[TypeVar(TS_SCHEMA, bound=TimeSeriesSchema)]) – The time-series enumerated inputssample_count (
int) – The frequency to sample the log valueskwargs (
TimeSeriesBundleInput[TypeVar(TS_SCHEMA_1, bound=TimeSeriesSchema)]) – The named time-series inputs
- lshift_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the
<<operator for time series types.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- lt_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[bool][source]
This represents the
<operator for time series types.- Return type:
- match_(pattern: TS[str], s: TS[str]) TSB[Match][source]
Matches the pattern in the string and returns the result and matching groups.
- Return type:
- max_(ts: TSL[TS[SCALAR], SIZE], default_value: TS[SCALAR]) TIME_SERIES_TYPE[source]
The
maxoperator for time series types.- Unary implies the max over the latest TS value for collection types, or running max for non-collection types
In the case of a running sum, a ‘reset’ signal may be provided, which resets the sum to zero when it ticks
- Binary or multi arg implies item-wise max over all the arguments for collection types,
or the maximum scalar value for scalar types
__strict__ controls whether the operator will tick if any of the arguments are missing
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- mean(ts: TSL[TIME_SERIES_TYPE, SIZE]) OUT[source]
This represents the
meanoperator for time series typesUnary implies the mean over the latest TS value for collection types, or running mean for non-collection types Binary or multi arg implies item-wise sum over all the arguments for collection types, or the sum of the scalar value for scalar types
- Return type:
Default
- merge(tsl: TSL[TIME_SERIES_TYPE, SIZE]) TIME_SERIES_TYPE[source]
Selects and returns the first of the values that tick (are modified) in the list provided. If more than one input is modified in the engine-cycle, it will return the first one that ticked in order of the list. if the inputs are TSDs: * If keys from multiple of the TSDs tick in the same cycle, the output will contain all the unique keys. * If the ticking keys are the same, the first value is returned in order of the list. * If disjoint is set True, the TSDs are assumed to have non-overlapping keys. This parameter should be set
True to optimise performance when merging disjoint TSDs.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- min_(ts: TSL[TS[SCALAR], SIZE], default_value: TS[SCALAR]) TIME_SERIES_TYPE[source]
This represents the
minoperator for time series types.- Unary implies the min over the latest TS value for collection types, or running min for non-collection types
In the case of a running sum, a ‘reset’ signal may be provided, which resets the sum to zero when it ticks
- Binary or multi arg implies item-wise min over all the arguments for collection types,
or the minimum scalar value for scalar types
__strict__ controls whether the operator will tick if any of the arguments are missing
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- mod_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the % operator for time series types.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- modified(ts: SIGNAL) TS[bool][source]
True if the time-series has been modified in this engine cycle, False otherwise. This is a live time-series as such it will actively tick False on the next engine cycle if the value is not modified again.
- Return type:
- mul_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the
*operator for time series types. Parameters: __strict__: bool: (default False) * if True will return nothing if either lhs or rhs is not valid or present * if False will return lhs or rhs if rhs or lhs respectively is not present- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- ne_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[bool][source]
This represents the
!=operator for time series types.- Return type:
- neg_(ts: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the unary
-operator for time series types.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- not_(ts: TIME_SERIES_TYPE) TS[bool][source]
This represents the unary not operator for time series types.
This must be called as
not_(ts)it is not possible to overload the standardnotoperator.- Return type:
- nothing(tp: type[OUT]) OUT[source]
Produces no ticks ever. This can be used in one of two ways:
`python nothing[TS[int]]() `or
`python nothing(TS[int]) `This is equivalent to None for time-series inputs.
- Return type:
Default
- null_sink(ts: TIME_SERIES_TYPE)[source]
A sink node that will consume the time-series and do nothing with it. This is useful when you want to consume a time-series but do not want to do anything with it.
- or_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TS[bool][source]
This represents the
oroperator for time series types.This operator does not substitute
or(since that is not possible in Python), but can be used as a functional equivalent foror.- Return type:
- partition(ts: TIME_SERIES_TYPE, partitions: TIME_SERIES_TYPE_1) OUT[source]
Splits a TSD into multiple TSDs given a mapping TSD. Its output is a TSD[K1, TSD[K, V]] for inputs of TSD[K, V] and TSD[K, K1] for mapping
- Return type:
TypeVar(OUT, bound=TimeSeries)
- pass_through_node(ts: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
Just passes the value through, this is useful for testing and for rank adjustment
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- pos_(ts: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the unary
+operator for time series types.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- pow_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the ** operator for time series types. Params: * divide_by_zero: DivideByZero - controls the behaviour when dividing by zero
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- print_(format_str: TS[str], args: TSB[TS_SCHEMA], kwargs: TSB[TS_SCHEMA_1])[source]
A sink node that will write the formatted string to the std out. This should be generally be used for debugging purposes and not be present in production code, instead use the log nodes for writing in a production context.
- Parameters:
format_str (
TimeSeriesValueInput[str]) – The format string as defined in formatargs (
TimeSeriesBundleInput[TypeVar(TS_SCHEMA, bound=TimeSeriesSchema)]) – The time-series enumerated inputskwargs (
TimeSeriesBundleInput[TypeVar(TS_SCHEMA_1, bound=TimeSeriesSchema)]) – The named time-series inputs
- race(tsl: TSL[TIME_SERIES_TYPE, SIZE]) TIME_SERIES_TYPE[source]
Forwards the first of the values that are valid in the list provided. If the first item becomes invalid then the next item to be valid is forwarded.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- rekey(ts: TIME_SERIES_TYPE, new_keys: TIME_SERIES_TYPE_1) OUT[source]
Re-keys the input time series to the provided key.
- Return type:
Default
- replace(pattern: TS[str], repl: TS[str], s: TS[str]) TS[str][source]
Replaces the pattern in the string with the replacement.
- Return type:
- resample(ts: TIME_SERIES_TYPE, period: timedelta) TIME_SERIES_TYPE[source]
Resamples the time series to tick at the specified period. For example,
resample(ts, timedelta(seconds=3))will produce a time series of ts that ticks every three seconds. This will always tick at the specified delay, even if the input time series does not tick.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- round_(ts: TS[float], n_digits: TS[int]) TS[float][source]
Rounds the input to the have the n_digits decimal places. This is currently implemented using the python round function.
- Return type:
- route_by_index(index_ts: TS[int], ts: TIME_SERIES_TYPE) TSL[TIME_SERIES_TYPE, SIZE][source]
Forwards a timeseries value to the ‘nth’ output according to the value of index_ts
- Return type:
TimeSeriesListInput[TypeVar(TIME_SERIES_TYPE, bound=TimeSeries),TypeVar(SIZE, bound=Size)]
- rshift_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
This represents the
>>operator for time series types.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- sample(signal: SIGNAL, ts: TIME_SERIES_TYPE) TIME_SERIES_TYPE[source]
Snaps the value of a time series (ts) on a tick from another time series (signal).
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- schedule(delay: timedelta, start: datetime, initial_delay: bool, max_ticks: int, use_wall_clock: bool) TS[bool][source]
Generates regular ticks in the graph that tick at the specified delay. For example,
schedule(timedelta(seconds=3))will produce a time series of type TS[bool] that will tick True every three seconds. The initial_delay parameter specifies whether the first tick should be delayed by the delay time or not and max_ticks specifies the maximum number of ticks to produce. on_wall_clock indicates if the wall clock time is to be used for the schedule. The default is to use engine time.- Return type:
- slice_(ts: TIME_SERIES_TYPE, start: INT_OR_TIME_DELTA, stop: INT_OR_TIME_DELTA, step_size: int) TIME_SERIES_TYPE[source]
Slices the time series from the start to the stop index stepped by the step size. Essentially combines
drop,takeandstepinto one operation. It works like python’s slice operator but along the ticks or time axis.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- split(s: TS[str], separator: str, maxsplits: int, to: type[OUT]) OUT[source]
- Return type:
Default
- Splits the string over the separator into one of the given types:
TS[Tuple[str, …]],
TS[Tuple[str, str]],
TSL[TS[str], SIZE]
- std(ts: TSL[TIME_SERIES_TYPE, SIZE]) OUT[source]
Calculates the standard deviation for time series types
Unary implies the std over the latest TS value for collection types, or running std for non-collection types Binary or multi arg implies item-wise std over all the arguments for collection types, or the std of the scalar value for scalar types
- Return type:
Default
- str_(ts: TIME_SERIES_TYPE) TS[str][source]
Converts the incoming time series to a string representation. Default implementation would be str(ts.value).
- Return type:
- step(ts: TIME_SERIES_TYPE, step_size: int) TIME_SERIES_TYPE[source]
Steps the time series by the specified number of ticks. This will skip ticks in the time series.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- str_(ts: TIME_SERIES_TYPE) TS[str][source]
Converts the incoming time series to a string representation. Default implementation would be str(ts.value).
- Return type:
- sub_(lhs: TIME_SERIES_TYPE, rhs: TIME_SERIES_TYPE_1) OUT[source]
This represents the
-operator for time series types.- Return type:
Default
- substr(s: TS[str], start: TS[int], end: TS[int]) TS[str][source]
Extracts a substring from the input string time series based on start and end positions.
- Parameters:
s (
TimeSeriesValueInput[str]) – Input string time series to perform extraction on.start (
TimeSeriesValueInput[int]) – Starting position (inclusive) of the substring. Negative values count from the endend (
TimeSeriesValueInput[int]) – Optional ending position (exclusive) of the substring. If None, extracts to the end of string.
- Return type:
- Returns:
Time series containing the extracted substring
- sum_(ts: TSL[TS[SCALAR], SIZE]) OUT[source]
This represents the
sumoperator for time series types, either as a binary or unary operator- Unary implies the sum over the latest TS value for collection types, or running sum for non-collection types.
In the case of a running sum, a ‘reset’ signal may be provided, which resets the sum to zero when it ticks
- Binary or multi arg implies item-wise sum over all the arguments for collection types,
or the sum of the scalar value for scalar types
- Return type:
Default
- symmetric_difference(tsl: TSL[TIME_SERIES_TYPE, SIZE]) OUT[source]
Performs the symmetric difference of the provided time-series values.
Symmetric difference is { p | p element of union(lhs, rhs), but not element of intersection(lhs, rhs) }
- Return type:
Default
- take(ts: TIME_SERIES_TYPE, count: INT_OR_TIME_DELTA) TIME_SERIES_TYPE[source]
filters out all ticks the input time series after
countinitial ticks or the given time series- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- throttle(ts: TIME_SERIES_TYPE, period: TS[timedelta], delay_first_tick: bool, use_wall_clock: bool) TIME_SERIES_TYPE[source]
Reduces the rate of ticks in a time series to the given period. It works like
resampleif the rate of ticks is higher than the period but unlikeresampledoes not produce ticks when the source time series does not tick.- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)
- to_json(ts: TIME_SERIES_TYPE, delta: bool) TS[str][source]
Converts the
tsto a JSON string.- Return type:
- to_window(ts: TS[SCALAR], period: INT_OR_TIME_DELTA, min_window_period: INT_OR_TIME_DELTA) TSW[SCALAR][source]
Converts the time-series to a time-series window.
When the window is an int, a cyclic buffer is created. If the window is a timedelta, then a deque is used to buffer the elements.
Note with time-deltas the buffer will contain at most the elements that fit within the window, so if you have 3 ticks at 1 microsecond intervals, and a window of 3 milliseconds, then the buffer will not be full until the 4th tick.
- Return type:
TimeSeriesWindowInput[TypeVar(SCALAR, bound=object),TypeVar(WINDOW_SIZE, bound=WindowSize),TypeVar(WINDOW_SIZE_MIN, bound=WindowSize)]
- type_(ts: TIME_SERIES_TYPE) TS[type][source]
Returns the type of the time-series value.
- Return type:
- uncollapse_keys(ts: TSD[tuple[K, K_1], TIME_SERIES_TYPE], remove_empty: bool) TSD[K, TSD[K_1, TIME_SERIES_TYPE]][source]
Given a TSD[Tuple[K, K1], V] uncollapse_keys will produce a nested TSD[K, TSD[K1, V]]. It is the reverse operation to
collapse_keys- Return type:
TimeSeriesDictInput[TypeVar(K, bound=Hashable),TimeSeriesDictInput[TypeVar(K_1, bound=Hashable),TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)]]
- union(tsl: TSL[TIME_SERIES_TYPE, SIZE]) OUT[source]
Performs a union of the provided time-series values.
Union is { p | p element of tsl[i] for i in range(len(tsl)) }
- Return type:
Default
- unpartition(ts: TIME_SERIES_TYPE) OUT[source]
Takes a nested TSD[K1, TSD[K, V]] and produces a TSD[K, V] by merging the inner TSDs
- Return type:
TypeVar(OUT, bound=TimeSeries)
- valid(ts: TIME_SERIES_TYPE, ts_value: TIME_SERIES_TYPE) TS[bool][source]
Ticks with False when the ts is not valid and True when it is.
- Return type:
- values_(ts: TIME_SERIES_TYPE) OUT[source]
Returns a tuple of the values in the dictionary. One options for a TSD, the values_ can be applied when the time-series value is a suitable TS[SCALAR], where the results are returned as a set. In this case use values_[TSS[…]](tsd)
- Return type:
Default
- var(ts: TSL[TIME_SERIES_TYPE, SIZE]) OUT[source]
Calculates the variance for time series types
Unary implies the var over the latest TS value for collection types, or running var for non-collection types Binary or multi arg implies item-wise var over all the arguments for collection types, or the vae of the scalar value for scalar types
- Return type:
Default
- zero(tp: type[TIME_SERIES_TYPE], op: WiringNodeClass) TIME_SERIES_TYPE[source]
This is a helper graph to create a zero time-series (for example, for the reduce function). The zero values are type and operation dependent, so both are provided. The datatype designers should overload this graph for their respective data types and return correct zero values for the operation.
- Return type:
TypeVar(TIME_SERIES_TYPE, bound=TimeSeries)