otp.string#

class string[source]#

Bases: str

OneTick data type representing string with length and varstring. To set string length use __getitem__. If the length is not set then the otp.string.DEFAULT_LENGTH length is used by default. In this case using otp.string is the same as using str. If the length is set to Ellipse it represents varstring. Varstring is used for returning variably sized strings.

Note

If you try to set value with length x to string[y] and x > y, value will be truncated to y length.

Examples

>>> t = otp.Tick(A='a')
>>> t = t.table(A=otp.string[10])
>>> t.schema
{'A': string[10]}

Example of truncation column value to set string length.

>>> t['A'] *= 100
>>> t['B'] = t['A'].str.len()
>>> t()
        Time           A   B
0 2003-12-01  aaaaaaaaaa  10

Example of string with default length.

>>> t = otp.Tick(A='a')
>>> t['A'] *= 100
>>> t['B'] = t['A'].str.len()
>>> t()
        Time                                                                 A   B
0 2003-12-01  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  64

Setting Ellipe as length represents varstring.

>>> t = otp.Tick(A='a')
>>> t = t.table(A=otp.string[...])
>>> t.schema
{'A': varstring}

Varstring length is multiplied.

>>> t['A'] *= 65
>>> t['B'] = t['A'].str.len()
>>> t()
        Time                                                                  A   B
0 2003-12-01  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa  65

otp.varstring is a shortcut:

>>> t = otp.Tick(A='a')
>>> t = t.table(A=otp.varstring)
>>> t.schema
{'A': varstring}
DEFAULT_LENGTH = 64#