Source code for onetick.py.utils.types
def get_type_that_includes(types):
import onetick.py.types as ott
def merge_two(type1, type2):
type_changed = False
b_type1, b_type2 = ott.get_base_type(type1), ott.get_base_type(type2)
if b_type1 != b_type2:
if {b_type1, b_type2} == {int, float}:
dtype = float
elif {b_type1, b_type2} == {ott.nsectime, ott.msectime}:
dtype = ott.nsectime
else:
raise ValueError(f"Incompatible types: {type1}, {type2}")
type_changed = True
elif issubclass(b_type1, str):
t1_length = ott.string.DEFAULT_LENGTH if type1 is str else type1.length
t2_length = ott.string.DEFAULT_LENGTH if type2 is str else type2.length
dtype = type2 if t1_length < t2_length else type1
if t1_length != t2_length:
type_changed = True # TODO: test
else:
dtype = type1
return dtype, type_changed
dtype = types[0]
type_changed = False
for other_dtype in types[1:]:
dtype, new_type_change = merge_two(dtype, other_dtype)
type_changed |= new_type_change
return dtype, type_changed
class adaptive(object):
"""
Used when you want to let know some parameters that it should be the same
as others.
"""
class adaptive_to_default(adaptive):
"""
If something is not specified and can not be deduced, then use the
default one
"""
class default(object):
"""
Used when you need to specify a default without evaluating it (e.g. default timezone)
"""
[docs]class range(object):
"""
Class that expresses OneTick ranges.
For example, if you want to express a range in the .split() method,
then you can use this range.
It has start and stop fields that allow you to define a range.
See also
--------
:py:meth:`~onetick.py.Source.split`.
Examples
--------
>>> data = otp.Ticks(X=[0.33, -5.1, otp.nan, 9.4])
>>> r1, r2, r3 = data.split(data['X'], [otp.nan, otp.range(0, 100)], default=True)
>>> r1()
Time X
0 2003-12-01 00:00:00.002 NaN
>>> r2()
Time X
0 2003-12-01 00:00:00.000 0.33
1 2003-12-01 00:00:00.003 9.40
>>> r3()
Time X
0 2003-12-01 00:00:00.001 -5.1
"""
def __init__(self, start, stop):
self.start = start
self.stop = stop