otp.state.tick_list#

tick_list(default_value=None, scope='query')[source]#

Defines a state tick list.

Parameters
  • default_value (eval query) – Eval query to initialize tick list from.

  • scope (str) – Scope for the state variable. Possible values are: query, branch, cross_symbol, all_inputs, all_outputs

Return type

onetick.py.core._internal._state_objects.TickList

Examples

>>> def fsq():
...     return otp.Ticks(B=[1, 2, 3])
>>> data = otp.Tick(A=1)
>>> data.state_vars['LIST'] = otp.state.tick_list(otp.eval(fsq))
>>> data = data.state_vars['LIST'].dump()
>>> otp.run(data)[['B']]
   B
0  1
1  2
2  3
class TickList(name, obj_ref, default_value, scope, schema=None, **kwargs)[source]#

Represents a tick list. This class should only be created with onetick.py.state.tick_list() function and should be added to the onetick.py.Source.state_vars() dictionary of the onetick.py.Source and can be accessed only via this dictionary.

Examples

>>> data = otp.Tick(A=1)
>>> data.state_vars['LIST'] = otp.state.tick_list()
>>> data = data.state_vars['LIST'].dump()

See also

TickSequenceTick

property schema: dict#
clear()[source]#

Clear tick list. Can be used in per-tick script or on Source directly.

inplace: bool

If True current source will be modified else modified copy will be returned. Makes sense only if used not in per-tick script.

Returns

  • if inplace is False and method is not used in per-tick script

  • then returns Source copy.

Examples

Can be used in per-tick script:

>>> def fun(tick):
...     tick.state_vars['LIST'].clear()
>>> data = otp.Tick(A=1)
>>> data.state_vars['LIST'] = otp.state.tick_list()
>>> data = data.script(fun)

Can be used in source columns operations:

>>> data = otp.Tick(A=1)
>>> data.state_vars['LIST'] = otp.state.tick_list(otp.eval(otp.Tick(A=1)))
>>> data = data.state_vars['LIST'].clear()
>>> data = data.state_vars['LIST'].dump()
>>> otp.run(data)
Empty DataFrame
Columns: []
Index: []
push_back(tick_object)[source]#

Add tick_object to the tick list. Can only be used in per-tick script.

Examples

>>> def fun(tick):
...     tick.state_vars['LIST'].push_back(tick)
>>> data = otp.Tick(A=1)
>>> data.state_vars['LIST'] = otp.state.tick_list()
>>> data = data.script(fun)
>>> data = data.state_vars['LIST'].dump()
>>> otp.run(data)
        Time  A
0 2003-12-01  1
get_size()[source]#

Get size of the tick list. Can be used in per-tick script or in Source operations directly.

Examples

Can be used in per-tick script:

>>> def fun(tick):
...     tick['B'] = tick.state_vars['LIST'].get_size()
>>> data = otp.Tick(A=1)
>>> data.state_vars['LIST'] = otp.state.tick_list()
>>> data = data.script(fun)

Can be used in source columns operations:

>>> data = otp.Tick(A=1)
>>> data.state_vars['LIST'] = otp.state.tick_list()
>>> data['B'] = data.state_vars['LIST'].get_size()
>>> otp.run(data)
        Time  A  B
0 2003-12-01  1  0
Return type

onetick.py.core.column_operations.base.Operation

size()[source]#

See also

get_size

Return type

onetick.py.core.column_operations.base.Operation

sort(field_name, field_type=None)[source]#

Sort the tick list in the ascending order over the specified field. Integer, float and datetime fields are supported for sorting. Implementation is per tick script which does a merge sort algorithm. Implemented algorithm is stable: it should not change the order of ticks with the same field value. Can only be used Source operations directly.

Parameters
  • field_name (str) – Name of the field over which to sort ticks

  • field_type (int, float, otp.msectime, otp.nsectime or None (default: None)) – Type of the field_name field. If None, type will be taken from the tick list schema.

Examples

>>> def fun(tick):
...     tick.state_vars['LIST'].push_back(tick)
>>> data = otp.Ticks([
...    ['offset', 'VALUE'],
...    [0, 2],
...    [0, 3],
...    [0, 1],
... ])
>>> data.state_vars['LIST'] = otp.state.tick_list()
>>> data = data.script(fun)
>>> data = data.agg(dict(NUM_TICKS=otp.agg.count()), bucket_time='end')
>>> data = data.state_vars['LIST'].sort('VALUE', int)
>>> data = data.state_vars['LIST'].dump()
>>> otp.run(data)
        Time  VALUE
0 2003-12-01  1
1 2003-12-01  2
2 2003-12-01  3
dump(propagate_input_ticks=False, when_to_dump='first_tick', delimiter=None, added_field_name_suffix=None)#

Propagates all ticks from a given tick sequence upon the arrival of input tick.

Preserves original timestamps from tick list/deque, if they fall into query start/end time range, and for ticks before start time and after end time, timestamps are changed to start time and end time correspondingly.

Parameters
  • propagate_input_ticks (bool) – Propagate input ticks or not.

  • when_to_dump (str) –

    • first_tick - Propagates once before input ticks. There must be at least one input tick.

    • before_tick - Propagates once before input ticks. Content will be propagated even if there are no input ticks.

  • delimiter ('tick', 'flag or None) –

    This parameter specifies the policy for adding the delimiter field. The name of the additional field is “DELIMITER” + added_field_name_suffix. Possible options are:

    • None - No additional field is added to propagated ticks.

    • ’tick’ - An extra tick is created after the last tick. Also, an additional column is added to output ticks. The extra tick has values of all fields set to the defaults (0,NaN,””), except the delimiter field, which is set to string “D”. All other ticks have this field’s value set to empty string.

    • ’flag’ - The delimiter field is appended to each output tick. The field’s value is empty for all ticks except the last tick of the tick sequence, which is string “D”.

  • added_field_name_suffix (str or None) – The suffix to add to the name of the additional field.

  • inplace (bool) – If True current source will be modified else modified copy will be returned

Return type

if inplace is False then returns Source copy.

Examples

>>> def another_query():
...     return otp.Ticks(B=[1, 2, 3])
>>> data = otp.Tick(A=1)
>>> data.state_vars['LIST'] = otp.state.tick_list(otp.eval(another_query))
>>> data = data.state_vars['LIST'].dump()
>>> otp.run(data)[['B']]
   B
0  1
1  2
2  3