otp.Source.add_suffix#

Source.add_suffix(suffix, inplace=False)[source]#

Addes suffix to all column names.

Parameters
  • suffix (str) – String suffix to add to all columns.

  • inplace (bool) – The flag controls whether operation should be applied inplace or not. If inplace=True, then it returns nothing. Otherwise method returns a new modified object.

Return type

Source or None

Examples

>>> data = otp.DataSource(db='SOME_DB', tick_type='TT', symbols='S1')
>>> data = data.add_suffix('_test')
>>> otp.run(data)
                     Time  X_test
0 2003-12-01 00:00:00.000       1
1 2003-12-01 00:00:00.001       2
2 2003-12-01 00:00:00.002       3
>>> data.schema
{'X_test': <class 'int'>}
>>> data = otp.DataSource(db='NYSE_TAQ', tick_type='TRD', symbols='AAPL')
>>> data = data.add_suffix('_test')
>>> otp.run(data, start=otp.dt(2022, 3, 1), end=otp.dt(2022, 3, 2))
                     Time  PRICE_test  SIZE_test
0 2022-03-01 00:00:00.000         1.3        100
1 2022-03-01 00:00:00.001         1.4         10
2 2022-03-01 00:00:00.002         1.4         50
>>> data.schema
{'PRICE_test': <class 'float'>}
>>> data = otp.Tick(X=1, XX=2)
>>> data.add_suffix('X')
Traceback (most recent call last):
  ...
AttributeError: Column XX already exists, please, use another suffix