onetick-py 1.171.0__py3-none-any.whl → 1.172.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
onetick/py/_version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  # This file was generated automatically. DO NOT CHANGE.
2
- VERSION = '1.171.0'
2
+ VERSION = '1.172.0'
@@ -23,8 +23,8 @@ def write(
23
23
  symbol: Union[str, 'otp.Column', None] = None,
24
24
  tick_type: Union[str, 'otp.Column', None] = None,
25
25
  date: Union[datetime.date, Type[adaptive], None] = adaptive,
26
- start: Optional[datetime.date] = None,
27
- end: Optional[datetime.date] = None,
26
+ start_date: Optional[datetime.date] = None,
27
+ end_date: Optional[datetime.date] = None,
28
28
  append: bool = False,
29
29
  keep_symbol_and_tick_type: Union[bool, Type[adaptive]] = adaptive,
30
30
  propagate: bool = True,
@@ -72,22 +72,21 @@ def write(
72
72
  date where to save data.
73
73
  Should be set to `None` if writing to accelerator or memory database.
74
74
  By default, it is set to `otp.config.default_date`.
75
- start: :py:class:`otp.datetime <onetick.py.datetime>` or None
75
+ start_date: :py:class:`otp.datetime <onetick.py.datetime>` or None
76
76
  Start date for data to save. It is inclusive.
77
77
  Cannot be used with ``date`` parameter.
78
78
  Also cannot be used with ``inplace`` set to ``True``.
79
79
  Should be set to `None` if writing to accelerator or memory database.
80
80
  By default, None.
81
- end: :py:class:`otp.datetime <onetick.py.datetime>` or None
82
- End date for data to save. It is exclusive, so be sure to set
83
- it to the next day after the last day in data.
81
+ end_date: :py:class:`otp.datetime <onetick.py.datetime>` or None
82
+ End date for data to save. It is inclusive.
84
83
  Cannot be used with ``date`` parameter.
85
84
  Also cannot be used with ``inplace`` set to ``True``.
86
85
  Should be set to `None` if writing to accelerator or memory database.
87
86
  By default, None.
88
87
  append: bool
89
88
  If False - data will be rewritten for this ``date``
90
- or range of dates (from ``start`` to ``end``),
89
+ or range of dates (from ``start_date`` to ``end_date``),
91
90
  otherwise data will be appended: new symbols are added,
92
91
  existing symbols can be modified (append new ticks, modify existing ticks).
93
92
  This option is not valid for accelerator databases.
@@ -100,12 +99,12 @@ def write(
100
99
  propagate: bool
101
100
  Propagate ticks after that event processor or not.
102
101
  out_of_range_tick_action: str
103
- Action to be executed if tick's timestamp's date is not ``date`` or between ``start`` or ``end``:
102
+ Action to be executed if tick's timestamp's date is not ``date`` or between ``start_date`` or ``end_date``:
104
103
 
105
104
  * `exception`: runtime exception will be raised
106
105
  * `ignore`: tick will not be written to the database
107
106
  * `load`: writes tick to the database anyway.
108
- Can be used only with ``date``, not with ``start``+``end``.
107
+ Can be used only with ``date``, not with ``start_date``+``end_date``.
109
108
 
110
109
  Default: `exception`
111
110
  timestamp: Column
@@ -134,7 +133,7 @@ def write(
134
133
  A flag controls whether operation should be applied inplace.
135
134
  If ``inplace=True``, then it returns nothing.
136
135
  Otherwise, method returns a new modified object.
137
- Cannot be ``True`` if ``start`` and ``end`` are set.
136
+ Cannot be ``True`` if ``start_date`` and ``end_date`` are set.
138
137
  kwargs:
139
138
  .. deprecated:: 1.21.0
140
139
 
@@ -176,6 +175,15 @@ def write(
176
175
  warnings.warn("Parameter 'keep_timestamp_field' is deprecated, use 'keep_timestamp'", FutureWarning)
177
176
  keep_timestamp = kwargs.pop('keep_timestamp_field')
178
177
 
178
+ if 'start' in kwargs:
179
+ warnings.warn("Parameter 'start' is deprecated, use 'start_date'", FutureWarning)
180
+ start_date = kwargs.pop('start')
181
+
182
+ if 'end' in kwargs:
183
+ warnings.warn("Parameter 'end' is deprecated, use 'end_date'", FutureWarning)
184
+ # Parameter 'end' was exclusive. Parameter 'end_date' is inclusive.
185
+ end_date = kwargs.pop('end') - otp.Day(1)
186
+
179
187
  if kwargs:
180
188
  raise TypeError(f'write() got unexpected arguments: {list(kwargs)}')
181
189
 
@@ -194,15 +202,18 @@ def write(
194
202
  f'Field "{field_name}" contains lowercase characters and cannot be saved to a Onetick database'
195
203
  )
196
204
 
197
- if date is not adaptive and (start or end):
198
- raise ValueError('date cannot be used with start+end')
205
+ if date is not adaptive and (start_date or end_date):
206
+ raise ValueError('date cannot be used with start_date+end_date')
199
207
 
200
- if date is adaptive and (start and end) and inplace:
208
+ if date is adaptive and (start_date and end_date) and inplace:
201
209
  # join_with_query and merge are used for multiple dates, so inplace is not supported
202
- raise ValueError('cannot run on multiple dates if inplace is True, use one value for date instead of start+end')
210
+ raise ValueError(
211
+ 'cannot run on multiple dates if inplace is True,'
212
+ ' use one value for date instead of start_date+end_date'
213
+ )
203
214
 
204
- if (start and not end) or (not start and end):
205
- raise ValueError('start and end should be both specified or both None')
215
+ if (start_date and not end_date) or (not start_date and end_date):
216
+ raise ValueError('start_date and end_date should be both specified or both None')
206
217
 
207
218
  if date is adaptive:
208
219
  date = configuration.config.default_date
@@ -244,10 +255,10 @@ def write(
244
255
  # let's ignore
245
256
  pass
246
257
  elif out_of_range_tick_action.upper() == 'LOAD':
247
- if start and end:
248
- raise ValueError('LOAD out_of_range_tick_action cannot be used with start+end, use date instead')
258
+ if start_date and end_date:
259
+ raise ValueError('LOAD out_of_range_tick_action cannot be used with start_date+end_date, use date instead')
249
260
  elif out_of_range_tick_action.upper() == 'EXCEPTION':
250
- if start and end:
261
+ if start_date and end_date:
251
262
  # WRITE_TO_ONETICK_DB use DAY_BOUNDARY_TZ and DAY_BOUNDARY_OFFSET
252
263
  # to check tick timestamp is out of range or not
253
264
  # so we mimic it here with THROW event processor
@@ -259,10 +270,12 @@ def write(
259
270
  {'DAY_BOUNDARY_TZ': '__DAY_BOUNDARY_TZ', 'DAY_BOUNDARY_OFFSET': '__DAY_BOUNDARY_OFFSET'}, inplace=True
260
271
  )
261
272
  self = self.join_with_query(src, symbol=f"{str(db)}::DUMMY", caching='per_symbol')
262
- start_formatted = start.strftime('%Y-%m-%d')
263
- end_formatted = end.strftime('%Y-%m-%d')
264
- convert_timestamp = self['TIMESTAMP'].dt.strftime('%Y%m%d%H%M%S.%J', timezone=self['__DAY_BOUNDARY_TZ'])
265
- start_op = otp.dt(start).to_operation(timezone=self['__DAY_BOUNDARY_TZ']) + self['__DAY_BOUNDARY_OFFSET']
273
+ timezone = self['__DAY_BOUNDARY_TZ']
274
+ offset = self['__DAY_BOUNDARY_OFFSET']
275
+ convert_timestamp = self['TIMESTAMP'].dt.strftime('%Y%m%d%H%M%S.%J', timezone=timezone)
276
+
277
+ start_formatted = start_date.strftime('%Y-%m-%d')
278
+ start_op = otp.dt(start_date).to_operation(timezone=timezone) + offset
266
279
  self.throw(
267
280
  where=(self['TIMESTAMP'] < start_op),
268
281
  message=(
@@ -270,11 +283,14 @@ def write(
270
283
  + convert_timestamp
271
284
  + ' of a tick, visible or hidden, '
272
285
  + f'earlier than {start_formatted} in timezone '
273
- + self['__DAY_BOUNDARY_TZ']
286
+ + timezone
274
287
  ),
275
288
  inplace=True,
276
289
  )
277
- end_op = otp.dt(end).to_operation(timezone=self['__DAY_BOUNDARY_TZ']) + self['__DAY_BOUNDARY_OFFSET']
290
+
291
+ end = end_date + otp.Day(1) # end_date is inclusive
292
+ end_formatted = end.strftime('%Y-%m-%d')
293
+ end_op = otp.dt(end).to_operation(timezone=timezone) + offset
278
294
  self.throw(
279
295
  where=(self['TIMESTAMP'] >= end_op),
280
296
  message=(
@@ -282,10 +298,11 @@ def write(
282
298
  + convert_timestamp
283
299
  + ' of a tick, visible or hidden, '
284
300
  + f'later than {end_formatted} in timezone '
285
- + self['__DAY_BOUNDARY_TZ']
301
+ + timezone
286
302
  ),
287
303
  inplace=True,
288
304
  )
305
+ self.drop(['__DAY_BOUNDARY_TZ', '__DAY_BOUNDARY_OFFSET'], inplace=True)
289
306
  else:
290
307
  raise ValueError(
291
308
  f'Unknown out_of_range_tick_action: {out_of_range_tick_action}.'
@@ -303,18 +320,16 @@ def write(
303
320
  use_context_of_query=use_context_of_query,
304
321
  )
305
322
 
306
- if start and end:
307
- days = (end - start).days
323
+ if start_date and end_date:
324
+ days = (end_date - start_date).days
308
325
  if days < 0:
309
- raise ValueError("Parameter 'start' must be less than parameter 'end'")
310
- if days == 0:
311
- raise ValueError("Parameters 'start' and 'end' must specify different dates")
326
+ raise ValueError("Parameter 'start_date' must be less than or equal to parameter 'end_date'")
312
327
  branches = []
313
- for i in range(days):
328
+ for i in range(days + 1):
314
329
  branch = self.copy()
315
330
  branch.sink(
316
331
  otq.WriteToOnetickDb(
317
- date=(start + otp.Day(i)).strftime('%Y%m%d'),
332
+ date=(start_date + otp.Day(i)).strftime('%Y%m%d'),
318
333
  propagate_ticks=propagate,
319
334
  out_of_range_tick_action='IGNORE',
320
335
  **kwargs,
@@ -14,10 +14,7 @@ class DatetimeSubtractionWarning(FutureWarning):
14
14
 
15
15
 
16
16
  def round(prev_op, precision):
17
- if precision is not None:
18
- return MethodResult(f'round_double({str(prev_op)},{str(precision)})', float)
19
- else:
20
- return MethodResult(f'round({str(prev_op)})', int)
17
+ return MethodResult(f'round_double({str(prev_op)},{str(precision)})', float)
21
18
 
22
19
 
23
20
  def isin(prev_op, items):
@@ -11,13 +11,11 @@ class _Accessor:
11
11
  self._base_column = base_column
12
12
 
13
13
  class Formatter(_Operation):
14
+ def __init__(self, dtype, formatter, op_params):
15
+ def op_func(*args, **kwargs):
16
+ return formatter(*args, **kwargs), dtype
14
17
 
15
- def __init__(self, base_column, dtype, formatter):
16
- super().__init__(dtype=dtype, op_params=[base_column])
17
- self._formatter = formatter
18
-
19
- def __str__(self):
20
- return self._formatter(str(self._op_params[0]))
18
+ super().__init__(op_func=op_func, op_params=op_params, dtype=dtype)
21
19
 
22
20
  def _preprocess_tz_and_format(self,
23
21
  timezone: typing.Union[Operation, str, None],
@@ -1,5 +1,6 @@
1
1
  from onetick.py import types as ott
2
2
  from onetick.py.core.column_operations.accessors._accessor import _Accessor
3
+ from onetick.py.core.column_operations.base import _Operation
3
4
 
4
5
 
5
6
  class _DecimalAccessor(_Accessor):
@@ -37,10 +38,16 @@ class _DecimalAccessor(_Accessor):
37
38
  3 3.142
38
39
  Name: X, dtype: object
39
40
  """
41
+ def formatter(column, _precision):
42
+ column = ott.value2str(column)
43
+ _precision = ott.value2str(_precision)
44
+
45
+ return f'decimal_to_string({column}, {_precision})'
46
+
40
47
  return _DecimalAccessor.Formatter(
41
- self._base_column,
42
- str,
43
- formatter=lambda x: f'decimal_to_string({x}, {precision})'
48
+ op_params=[self._base_column, precision],
49
+ dtype=str,
50
+ formatter=formatter,
44
51
  )
45
52
 
46
53
  def cmp(self, other, eps):
@@ -83,10 +90,15 @@ class _DecimalAccessor(_Accessor):
83
90
  4 1.0
84
91
  Name: X, dtype: float64
85
92
  """
86
- other = ott.value2str(other)
87
- eps = ott.value2str(eps)
93
+
94
+ def formatter(column, _other, _eps):
95
+ column = ott.value2str(column)
96
+ _other = ott.value2str(_other)
97
+ _eps = ott.value2str(_eps)
98
+ return f'decimal_compare({column}, {_other}, {_eps})'
99
+
88
100
  return _DecimalAccessor.Formatter(
89
- self._base_column,
90
- ott.decimal,
91
- formatter=lambda x: f'decimal_compare({x}, {other}, {eps})'
101
+ op_params=[self._base_column, other, eps],
102
+ dtype=ott.decimal,
103
+ formatter=formatter,
92
104
  )
@@ -1,6 +1,7 @@
1
1
  from typing import Union
2
2
 
3
3
  from onetick.py import configuration, utils
4
+ from onetick.py import types as ott
4
5
  from onetick.py.core.column_operations.accessors._accessor import _Accessor
5
6
  from onetick.py.backports import Literal
6
7
  from onetick.py.types import datetime, value2str
@@ -76,14 +77,17 @@ class _DtAccessor(_Accessor):
76
77
  """
77
78
  if timezone is utils.default:
78
79
  timezone = configuration.config.tz
79
- timezone, format_str = self._preprocess_tz_and_format(timezone, format)
80
80
 
81
- def formatter(x):
82
- return f'nsectime_format({format_str},{x},{timezone})'
81
+ def formatter(column, _format, _timezone):
82
+ column = ott.value2str(column)
83
+ _timezone, _format = self._preprocess_tz_and_format(_timezone, _format)
84
+ return f'nsectime_format({_format},{column},{_timezone})'
83
85
 
84
- return _DtAccessor.Formatter(self._base_column,
85
- str,
86
- formatter=formatter)
86
+ return _DtAccessor.Formatter(
87
+ op_params=[self._base_column, format, timezone],
88
+ dtype=str,
89
+ formatter=formatter,
90
+ )
87
91
 
88
92
  def date(self):
89
93
  """
@@ -103,7 +107,9 @@ class _DtAccessor(_Accessor):
103
107
  return self.strftime(format_str, None).str.to_datetime(format_str, None)
104
108
 
105
109
  @docstring(parameters=[_timezone_doc], add_self=True)
106
- def day_of_week(self, start_index: int = 1, start_day: Literal['monday', 'sunday'] = 'monday', timezone=None):
110
+ def day_of_week(
111
+ self, start_index: Union[int, _Operation] = 1, start_day: Literal['monday', 'sunday'] = 'monday', timezone=None,
112
+ ):
107
113
  """
108
114
  Return the day of the week.
109
115
 
@@ -112,7 +118,7 @@ class _DtAccessor(_Accessor):
112
118
 
113
119
  Parameters
114
120
  ----------
115
- start_index: int
121
+ start_index: int or Operation
116
122
  Sunday index.
117
123
  start_day: 'monday' or 'sunday'
118
124
  Day that will be denoted with ``start_index``
@@ -135,19 +141,22 @@ class _DtAccessor(_Accessor):
135
141
  if start_day not in ['monday', 'sunday']:
136
142
  raise ValueError(f"'start_day' parameter ({start_day}) not in ['monday', 'sunday']")
137
143
 
138
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
139
-
140
- def formatter(x):
141
- format_ = f'day_of_week({x},{timezone})'
142
- if start_day == 'monday':
144
+ def formatter(column, _start_index, _start_day, _timezone):
145
+ column = ott.value2str(column)
146
+ _start_index = ott.value2str(_start_index)
147
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
148
+ format_ = f'day_of_week({column},{_timezone})'
149
+ if _start_day == 'monday':
143
150
  # CASE should be uppercased because it can be used in per-tick script
144
151
  format_ = f'CASE({format_}, 0, 7, {format_})-1'
145
- format_ += f'+{start_index}'
152
+ format_ += f'+{_start_index}'
146
153
  return format_
147
154
 
148
- return _DtAccessor.Formatter(self._base_column,
149
- int,
150
- formatter=formatter)
155
+ return _DtAccessor.Formatter(
156
+ op_params=[self._base_column, start_index, start_day, timezone],
157
+ dtype=int,
158
+ formatter=formatter,
159
+ )
151
160
 
152
161
  @docstring(parameters=[_timezone_doc], add_self=True)
153
162
  def day_name(self, timezone=None):
@@ -168,11 +177,16 @@ class _DtAccessor(_Accessor):
168
177
  5 2022-05-15 Sunday
169
178
  6 2022-05-16 Monday
170
179
  """
171
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
180
+ def formatter(column, _timezone):
181
+ column = ott.value2str(column)
182
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
183
+ return f'DAYNAME({column},{_timezone})'
172
184
 
173
- return _DtAccessor.Formatter(self._base_column,
174
- str,
175
- formatter=lambda x: f'DAYNAME({x},{timezone})')
185
+ return _DtAccessor.Formatter(
186
+ op_params=[self._base_column, timezone],
187
+ dtype=str,
188
+ formatter=formatter,
189
+ )
176
190
 
177
191
  @docstring(parameters=[_timezone_doc], add_self=True)
178
192
  def day_of_month(self, timezone=None):
@@ -193,11 +207,16 @@ class _DtAccessor(_Accessor):
193
207
  5 2022-05-15 15
194
208
  6 2022-05-16 16
195
209
  """
196
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
210
+ def formatter(column, _timezone):
211
+ column = ott.value2str(column)
212
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
213
+ return f'DAYOFMONTH({column},{_timezone})'
197
214
 
198
- return _DtAccessor.Formatter(self._base_column,
199
- int,
200
- formatter=lambda x: f'DAYOFMONTH({x},{timezone})')
215
+ return _DtAccessor.Formatter(
216
+ op_params=[self._base_column, timezone],
217
+ dtype=int,
218
+ formatter=formatter,
219
+ )
201
220
 
202
221
  @docstring(parameters=[_timezone_doc], add_self=True)
203
222
  def day_of_year(self, timezone=None):
@@ -218,11 +237,16 @@ class _DtAccessor(_Accessor):
218
237
  5 2022-05-15 135
219
238
  6 2022-05-16 136
220
239
  """
221
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
240
+ def formatter(column, _timezone):
241
+ column = ott.value2str(column)
242
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
243
+ return f'DAYOFYEAR({column},{_timezone})'
222
244
 
223
- return _DtAccessor.Formatter(self._base_column,
224
- int,
225
- formatter=lambda x: f'DAYOFYEAR({x},{timezone})')
245
+ return _DtAccessor.Formatter(
246
+ op_params=[self._base_column, timezone],
247
+ dtype=int,
248
+ formatter=formatter,
249
+ )
226
250
 
227
251
  @docstring(parameters=[_timezone_doc], add_self=True)
228
252
  def hour(self, timezone=None):
@@ -243,11 +267,16 @@ class _DtAccessor(_Accessor):
243
267
  5 2022-05-01 15:00:06 15
244
268
  6 2022-05-01 16:00:06 16
245
269
  """
246
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
270
+ def formatter(column, _timezone):
271
+ column = ott.value2str(column)
272
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
273
+ return f'HOUR({column},{_timezone})'
247
274
 
248
- return _DtAccessor.Formatter(self._base_column,
249
- int,
250
- formatter=lambda x: f'HOUR({x},{timezone})')
275
+ return _DtAccessor.Formatter(
276
+ op_params=[self._base_column, timezone],
277
+ dtype=int,
278
+ formatter=formatter,
279
+ )
251
280
 
252
281
  @docstring(parameters=[_timezone_doc], add_self=True)
253
282
  def minute(self, timezone=None):
@@ -269,11 +298,16 @@ class _DtAccessor(_Accessor):
269
298
  5 2022-05-01 15:15:06 15
270
299
  6 2022-05-01 15:16:06 16
271
300
  """
272
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
301
+ def formatter(column, _timezone):
302
+ column = ott.value2str(column)
303
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
304
+ return f'MINUTE({column},{_timezone})'
273
305
 
274
- return _DtAccessor.Formatter(self._base_column,
275
- int,
276
- formatter=lambda x: f'MINUTE({x},{timezone})')
306
+ return _DtAccessor.Formatter(
307
+ op_params=[self._base_column, timezone],
308
+ dtype=int,
309
+ formatter=formatter,
310
+ )
277
311
 
278
312
  @docstring(parameters=[_timezone_doc], add_self=True)
279
313
  def second(self, timezone=None):
@@ -294,11 +328,16 @@ class _DtAccessor(_Accessor):
294
328
  5 2022-05-01 15:11:15 15
295
329
  6 2022-05-01 15:11:16 16
296
330
  """
297
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
331
+ def formatter(column, _timezone):
332
+ column = ott.value2str(column)
333
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
334
+ return f'SECOND({column},{_timezone})'
298
335
 
299
- return _DtAccessor.Formatter(self._base_column,
300
- int,
301
- formatter=lambda x: f'SECOND({x},{timezone})')
336
+ return _DtAccessor.Formatter(
337
+ op_params=[self._base_column, timezone],
338
+ dtype=int,
339
+ formatter=formatter,
340
+ )
302
341
 
303
342
  @docstring(parameters=[_timezone_doc], add_self=True)
304
343
  def month(self, timezone=None):
@@ -320,11 +359,16 @@ class _DtAccessor(_Accessor):
320
359
  6 2022-09-01 9
321
360
  7 2022-10-01 10
322
361
  """
323
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
362
+ def formatter(column, _timezone):
363
+ column = ott.value2str(column)
364
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
365
+ return f'MONTH({column},{_timezone})'
324
366
 
325
- return _DtAccessor.Formatter(self._base_column,
326
- int,
327
- formatter=lambda x: f'MONTH({x},{timezone})')
367
+ return _DtAccessor.Formatter(
368
+ op_params=[self._base_column, timezone],
369
+ dtype=int,
370
+ formatter=formatter,
371
+ )
328
372
 
329
373
  @docstring(parameters=[_timezone_doc], add_self=True)
330
374
  def month_name(self, timezone=None):
@@ -346,11 +390,16 @@ class _DtAccessor(_Accessor):
346
390
  6 2022-09-01 Sep
347
391
  7 2022-10-01 Oct
348
392
  """
349
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
393
+ def formatter(column, _timezone):
394
+ column = ott.value2str(column)
395
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
396
+ return f'MONTHNAME({column},{_timezone})'
350
397
 
351
- return _DtAccessor.Formatter(self._base_column,
352
- str,
353
- formatter=lambda x: f'MONTHNAME({x},{timezone})')
398
+ return _DtAccessor.Formatter(
399
+ op_params=[self._base_column, timezone],
400
+ dtype=str,
401
+ formatter=formatter,
402
+ )
354
403
 
355
404
  @docstring(parameters=[_timezone_doc], add_self=True)
356
405
  def quarter(self, timezone=None):
@@ -372,11 +421,16 @@ class _DtAccessor(_Accessor):
372
421
  6 2022-09-01 3
373
422
  7 2022-10-01 4
374
423
  """
375
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
424
+ def formatter(column, _timezone):
425
+ column = ott.value2str(column)
426
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
427
+ return f'QUARTER({column},{_timezone})'
376
428
 
377
- return _DtAccessor.Formatter(self._base_column,
378
- int,
379
- formatter=lambda x: f'QUARTER({x},{timezone})')
429
+ return _DtAccessor.Formatter(
430
+ op_params=[self._base_column, timezone],
431
+ dtype=int,
432
+ formatter=formatter,
433
+ )
380
434
 
381
435
  @docstring(parameters=[_timezone_doc], add_self=True)
382
436
  def year(self, timezone=None):
@@ -398,11 +452,16 @@ class _DtAccessor(_Accessor):
398
452
  6 2029-03-01 2029
399
453
  7 2030-03-01 2030
400
454
  """
401
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
455
+ def formatter(column, _timezone):
456
+ column = ott.value2str(column)
457
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
458
+ return f'YEAR({column},{_timezone})'
402
459
 
403
- return _DtAccessor.Formatter(self._base_column,
404
- int,
405
- formatter=lambda x: f'YEAR({x},{timezone})')
460
+ return _DtAccessor.Formatter(
461
+ op_params=[self._base_column, timezone],
462
+ dtype=int,
463
+ formatter=formatter,
464
+ )
406
465
 
407
466
  @docstring(parameters=[_timezone_doc], add_self=True)
408
467
  def date_trunc(self,
@@ -434,12 +493,17 @@ class _DtAccessor(_Accessor):
434
493
  5 2020-11-11 05:04:13.101737879 2020-11-11 05:04:13.101000000 millisecond
435
494
  6 2020-11-11 05:04:13.101737879 2020-11-11 05:04:13.101737879 nanosecond
436
495
  """
437
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
438
- date_part = value2str(date_part)
439
-
440
- return _DtAccessor.Formatter(self._base_column,
441
- datetime,
442
- formatter=lambda x: f'DATE_TRUNC({date_part},{x},{timezone})')
496
+ def formatter(column, _date_part, _timezone):
497
+ column = ott.value2str(column)
498
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
499
+ _date_part = value2str(_date_part)
500
+ return f'DATE_TRUNC({_date_part},{column},{_timezone})'
501
+
502
+ return _DtAccessor.Formatter(
503
+ op_params=[self._base_column, date_part, timezone],
504
+ dtype=datetime,
505
+ formatter=formatter,
506
+ )
443
507
 
444
508
  @docstring(parameters=[_timezone_doc], add_self=True)
445
509
  def week(self, timezone=None):
@@ -461,8 +525,13 @@ class _DtAccessor(_Accessor):
461
525
  6 2020-09-01 36
462
526
  7 2020-10-01 40
463
527
  """
464
- timezone, _ = self._preprocess_tz_and_format(timezone, '')
465
-
466
- return _DtAccessor.Formatter(self._base_column,
467
- int,
468
- formatter=lambda x: f'WEEK({x},{timezone})')
528
+ def formatter(column, _timezone):
529
+ column = ott.value2str(column)
530
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
531
+ return f'WEEK({column},{_timezone})'
532
+
533
+ return _DtAccessor.Formatter(
534
+ op_params=[self._base_column, timezone],
535
+ dtype=int,
536
+ formatter=formatter,
537
+ )
@@ -1,5 +1,6 @@
1
1
  from onetick.py import types as ott
2
2
  from onetick.py.core.column_operations.accessors._accessor import _Accessor
3
+ from onetick.py.core.column_operations.base import _Operation
3
4
 
4
5
 
5
6
  class _FloatAccessor(_Accessor):
@@ -61,11 +62,18 @@ class _FloatAccessor(_Accessor):
61
62
  Name: X, dtype: object
62
63
  """
63
64
  dtype = ott.string[length] if isinstance(length, int) else str
64
- length = ott.value2str(length)
65
- precision = ott.value2str(precision)
66
- return _FloatAccessor.Formatter(self._base_column,
67
- dtype,
68
- formatter=lambda x: f"str({x}, {length}, {precision})")
65
+
66
+ def formatter(column, _length, _precision):
67
+ column = ott.value2str(column)
68
+ _length = ott.value2str(_length)
69
+ _precision = ott.value2str(_precision)
70
+ return f"str({column}, {_length}, {_precision})"
71
+
72
+ return _FloatAccessor.Formatter(
73
+ op_params=[self._base_column, length, precision],
74
+ dtype=dtype,
75
+ formatter=formatter,
76
+ )
69
77
 
70
78
  def cmp(self, other, eps):
71
79
  """
@@ -110,11 +118,17 @@ class _FloatAccessor(_Accessor):
110
118
  4 1.0
111
119
  Name: X, dtype: float64
112
120
  """
113
- other = ott.value2str(other)
114
- eps = ott.value2str(eps)
115
- return _FloatAccessor.Formatter(self._base_column,
116
- float,
117
- formatter=lambda x: f"double_compare({x}, {other}, {eps})")
121
+ def formatter(column, _other, _eps):
122
+ column = ott.value2str(column)
123
+ _other = ott.value2str(_other)
124
+ _eps = ott.value2str(_eps)
125
+ return f"double_compare({column}, {_other}, {_eps})"
126
+
127
+ return _FloatAccessor.Formatter(
128
+ op_params=[self._base_column, other, eps],
129
+ dtype=float,
130
+ formatter=formatter,
131
+ )
118
132
 
119
133
  def eq(self, other, delta):
120
134
  """
@@ -153,8 +167,14 @@ class _FloatAccessor(_Accessor):
153
167
  4 0.0
154
168
  Name: X, dtype: float64
155
169
  """
156
- other = ott.value2str(other)
157
- delta = ott.value2str(delta)
158
- return _FloatAccessor.Formatter(self._base_column,
159
- bool,
160
- formatter=lambda x: f"abs({x} - {other}) <= {delta}")
170
+ def formatter(column, _other, _delta):
171
+ column = ott.value2str(column)
172
+ _other = ott.value2str(_other)
173
+ _delta = ott.value2str(_delta)
174
+ return f"abs({column} - {_other}) <= {_delta}"
175
+
176
+ return _FloatAccessor.Formatter(
177
+ op_params=[self._base_column, other, delta],
178
+ dtype=bool,
179
+ formatter=formatter,
180
+ )
@@ -21,13 +21,6 @@ class _StrAccessor(_Accessor):
21
21
  >>> data = otp.Ticks(X=['some string'])
22
22
  >>> data["Y"] = data["X"].str.<function_name>() # doctest: +SKIP
23
23
  """
24
- class Formatter(_Operation):
25
- def __init__(self, dtype, formatter, op_params):
26
-
27
- def op_func(*args, **kwargs):
28
- return formatter(*args, **kwargs), dtype
29
-
30
- super().__init__(op_func=op_func, op_params=op_params, dtype=dtype)
31
24
 
32
25
  def to_datetime(self,
33
26
  format='%Y/%m/%d %H:%M:%S.%J',
@@ -139,9 +139,16 @@ class Operation:
139
139
  """
140
140
  return Expr(self)
141
141
 
142
- def round(self, precision=None):
142
+ def round(self, precision=0):
143
143
  """
144
- Rounds input column with specified `precision`.
144
+ Rounds input column with specified ``precision``.
145
+
146
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
147
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity.
148
+
149
+ For values that are exactly half-way between two integers (when the fraction part of value is exactly 0.5),
150
+ the rounding method used here is *upwards*, which returns the bigger number.
151
+ For other rounding methods see :func:`otp.math.round <onetick.py.math.round>` function.
145
152
 
146
153
  Parameters
147
154
  ----------
@@ -161,8 +168,8 @@ class Operation:
161
168
  >>> t['C'] = t['A'].round(2)
162
169
  >>> t['D'] = t['A'].round(-2)
163
170
  >>> otp.run(t)
164
- Time A B C D
165
- 0 2003-12-01 1234.5678 1235 1234.57 1200.0
171
+ Time A B C D
172
+ 0 2003-12-01 1234.5678 1235.0 1234.57 1200.0
166
173
 
167
174
  Returns
168
175
  -------
@@ -505,31 +512,84 @@ class Operation:
505
512
  """
506
513
  return _Operation(_methods.abs, [self])
507
514
 
508
- def __round__(self, precision=None):
515
+ def __round__(self, precision=0):
509
516
  """
510
517
  Rounds value with specified ``precision``.
511
518
 
519
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
520
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity.
521
+
522
+ For values that are exactly half-way between two integers (when the fraction part of value is exactly 0.5),
523
+ the rounding method used here is *upwards*, which returns the bigger number.
524
+ For other rounding methods see :func:`otp.math.round <onetick.py.math.round>` function.
525
+
526
+ See also
527
+ --------
528
+ :func:`otp.math.round <onetick.py.math.round>`
529
+ :func:`otp.math.floor <onetick.py.math.floor>`
530
+ :func:`otp.math.ceil <onetick.py.math.ceil>`
531
+
512
532
  Parameters
513
533
  ----------
514
534
  precision: int
515
535
  Number from -12 to 12.
516
536
  Positive precision is precision after the floating point.
517
- Negative precision is precision before the floating point.
537
+ Negative precision is precision before the floating point (and the fraction part is dropped in this case).
518
538
 
519
539
  Examples
520
540
  --------
521
- >>> t = otp.Tick(A=1234.5678)
522
- >>> t['B'] = round(t['A'])
523
- >>> t['C'] = round(t['A'], 2)
524
- >>> t['D'] = round(t['A'], -2)
541
+
542
+ By default the ``precision`` is zero and the number is rounded to the closest integer number
543
+ (and to the bigger number when the fraction part of value is exactly 0.5):
544
+
545
+ >>> t = otp.Ticks(A=[-123.45, 123.45, 123.5])
546
+ >>> t['ROUND'] = round(t['A'])
547
+ >>> otp.run(t)
548
+ Time A ROUND
549
+ 0 2003-12-01 00:00:00.000 -123.45 -123.0
550
+ 1 2003-12-01 00:00:00.001 123.45 123.0
551
+ 2 2003-12-01 00:00:00.002 123.50 124.0
552
+
553
+ Positive precision truncates to the number of digits *after* floating point:
554
+
555
+ >>> t = otp.Ticks(A=[-123.45, 123.45])
556
+ >>> t['ROUND1'] = round(t['A'], 1)
557
+ >>> t['ROUND2'] = round(t['A'], 2)
558
+ >>> otp.run(t)
559
+ Time A ROUND1 ROUND2
560
+ 0 2003-12-01 00:00:00.000 -123.45 -123.4 -123.45
561
+ 1 2003-12-01 00:00:00.001 123.45 123.5 123.45
562
+
563
+ Negative precision truncates to the number of digits *before* floating point
564
+ (and the fraction part is dropped in this case):
565
+
566
+ >>> t = otp.Ticks(A=[-123.45, 123.45])
567
+ >>> t['ROUND_M1'] = round(t['A'], -1)
568
+ >>> t['ROUND_M2'] = round(t['A'], -2)
569
+ >>> otp.run(t)
570
+ Time A ROUND_M1 ROUND_M2
571
+ 0 2003-12-01 00:00:00.000 -123.45 -120.0 -100.0
572
+ 1 2003-12-01 00:00:00.001 123.45 120.0 100.0
573
+
574
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
575
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity in all cases:
576
+
577
+ >>> t = otp.Ticks(A=[otp.inf, -otp.inf, otp.nan])
578
+ >>> t['ROUND_0'] = round(t['A'])
579
+ >>> t['ROUND_P2'] = round(t['A'], 2)
580
+ >>> t['ROUND_M2'] = round(t['A'], -2)
525
581
  >>> otp.run(t)
526
- Time A B C D
527
- 0 2003-12-01 1234.5678 1235 1234.57 1200.0
582
+ Time A ROUND_0 ROUND_P2 ROUND_M2
583
+ 0 2003-12-01 00:00:00.000 inf inf inf inf
584
+ 1 2003-12-01 00:00:00.001 -inf -inf -inf -inf
585
+ 2 2003-12-01 00:00:00.002 NaN NaN NaN NaN
528
586
 
529
587
  Returns
530
588
  -------
531
589
  Operation
532
590
  """
591
+ if precision is None:
592
+ precision = 0
533
593
  return _Operation(_methods.round, [self, precision])
534
594
 
535
595
  def __neg__(self):
@@ -1,3 +1,4 @@
1
+ from onetick import py as otp
1
2
  from onetick.py import configuration
2
3
  from onetick.py.otq import otq
3
4
 
@@ -94,8 +95,8 @@ class MultiOutputSource:
94
95
  # we create a set of keys for all outputs and see if all sets are connected;
95
96
  # two sets are connected if they have any key in common
96
97
 
97
- if len(outputs) <= 1:
98
- raise ValueError('At least two branches should be passed to a MultiOutputSource object')
98
+ if len(outputs) < 1:
99
+ raise ValueError('At least one branch should be passed to a MultiOutputSource object')
99
100
 
100
101
  def get_history_key_set(hist):
101
102
  keys = set()
@@ -155,6 +156,41 @@ class MultiOutputSource:
155
156
  def _side_branch_list(self):
156
157
  return list(self.__side_branches.values())
157
158
 
159
+ def get_branch(self, branch_name: str) -> otp.Source:
160
+ """
161
+ Retrieve a branch by its name.
162
+
163
+ Parameters
164
+ ----------
165
+ branch_name : str
166
+ The name of the branch to retrieve.
167
+
168
+ Returns
169
+ -------
170
+ otp.Source
171
+ The branch corresponding to the given name.
172
+ """
173
+ if branch_name == self.__main_branch_name:
174
+ return self.__main_branch
175
+
176
+ branch = self.__side_branches.get(branch_name)
177
+ if branch is None:
178
+ raise ValueError(f'Branch name "{branch_name}" not found among the outputs!')
179
+
180
+ return branch
181
+
182
+ @property
183
+ def main_branch(self) -> otp.Source:
184
+ """
185
+ Get the main branch.
186
+
187
+ Returns
188
+ -------
189
+ otp.Source
190
+ The main branch.
191
+ """
192
+ return self.__main_branch
193
+
158
194
  def _prepare_for_execution(self, symbols=None, start=None, end=None, start_time_expression=None,
159
195
  end_time_expression=None, timezone=None,
160
196
  has_output=None, # NOSONAR
@@ -191,3 +227,6 @@ class MultiOutputSource:
191
227
  end=end,
192
228
  timezone=timezone,
193
229
  add_passthrough=False)
230
+
231
+ def _store_in_tmp_otq(self, *args, **kwargs):
232
+ return self.main_branch._store_in_tmp_otq(*args, **kwargs)
onetick/py/db/db.py CHANGED
@@ -110,8 +110,8 @@ def write_to_db(src: 'otp.Source',
110
110
  if timezone is None:
111
111
  timezone = configuration.config.tz
112
112
  if date is None or date is otp.adaptive:
113
- kwargs['start'] = start
114
- kwargs['end'] = end
113
+ kwargs['start_date'] = start
114
+ kwargs['end_date'] = end
115
115
  else:
116
116
  kwargs['date'] = date
117
117
 
onetick/py/functions.py CHANGED
@@ -2033,7 +2033,13 @@ def _add_element(cur_res, element, format_spec_additional=None):
2033
2033
  elif issubclass(element.dtype, float) and re.fullmatch(r'\.\d+f', format_spec_additional):
2034
2034
  # float has strange behavior when precision=0
2035
2035
  decimal_elem = element.apply(ott.decimal)
2036
- cur_res += decimal_elem.decimal.str(re.findall(r'\d+', format_spec_additional)[0])
2036
+ precision_str = re.findall(r'\d+', format_spec_additional)[0]
2037
+ try:
2038
+ precision = int(precision_str)
2039
+ except ValueError as exc:
2040
+ raise ValueError('Incorrect value for `precision` for formatting decimal number') from exc
2041
+
2042
+ cur_res += decimal_elem.decimal.str(precision)
2037
2043
  elif issubclass(element.dtype, (ott.nsectime, ott.msectime)):
2038
2044
  cur_res += element.dt.strftime(format_spec_additional)
2039
2045
  else:
onetick/py/math.py CHANGED
@@ -760,7 +760,12 @@ def gcd(value1, value2):
760
760
 
761
761
  def floor(value):
762
762
  """
763
- Returns a long integer value representing the largest integer that is less than or equal to the ``value``.
763
+ Returns a float value representing the largest number that is less than or equal to the ``value``.
764
+
765
+ Note
766
+ ----
767
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
768
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity.
764
769
 
765
770
  Parameters
766
771
  ----------
@@ -772,29 +777,41 @@ def floor(value):
772
777
 
773
778
  Examples
774
779
  --------
775
- >>> data = otp.Ticks(A=[-1.7, -1.5, -1.2, -1, 0 , 1, 1.2, 1.5, 1.7])
780
+ >>> data = otp.Ticks(A=[-1.7, -1.5, -1.2, -1, 0 , 1, 1.2, 1.5, 1.7, -otp.inf, otp.inf, otp.nan])
776
781
  >>> data['FLOOR'] = otp.math.floor(data['A'])
777
782
  >>> otp.run(data)
778
- Time A FLOOR
779
- 0 2003-12-01 00:00:00.000 -1.7 -2
780
- 1 2003-12-01 00:00:00.001 -1.5 -2
781
- 2 2003-12-01 00:00:00.002 -1.2 -2
782
- 3 2003-12-01 00:00:00.003 -1.0 -1
783
- 4 2003-12-01 00:00:00.004 0.0 0
784
- 5 2003-12-01 00:00:00.005 1.0 1
785
- 6 2003-12-01 00:00:00.006 1.2 1
786
- 7 2003-12-01 00:00:00.007 1.5 1
787
- 8 2003-12-01 00:00:00.008 1.7 1
788
- """
783
+ Time A FLOOR
784
+ 0 2003-12-01 00:00:00.000 -1.7 -2.0
785
+ 1 2003-12-01 00:00:00.001 -1.5 -2.0
786
+ 2 2003-12-01 00:00:00.002 -1.2 -2.0
787
+ 3 2003-12-01 00:00:00.003 -1.0 -1.0
788
+ 4 2003-12-01 00:00:00.004 0.0 0.0
789
+ 5 2003-12-01 00:00:00.005 1.0 1.0
790
+ 6 2003-12-01 00:00:00.006 1.2 1.0
791
+ 7 2003-12-01 00:00:00.007 1.5 1.0
792
+ 8 2003-12-01 00:00:00.008 1.7 1.0
793
+ 9 2003-12-01 00:00:00.009 -inf -inf
794
+ 10 2003-12-01 00:00:00.010 inf inf
795
+ 11 2003-12-01 00:00:00.011 NaN NaN
796
+ """
797
+ def fun(v):
798
+ v = value2str(v)
799
+ return f'CASE({v}, NAN(), NAN(), INFINITY(), INFINITY(), -INFINITY(), -INFINITY(), FLOOR({v}) * 1.0)', float
800
+
789
801
  return _Operation(
790
- op_func=lambda v: (f'FLOOR({value2str(v)})', int),
802
+ op_func=fun,
791
803
  op_params=[value],
792
804
  )
793
805
 
794
806
 
795
807
  def ceil(value):
796
808
  """
797
- Returns a long integer value representing the smallest integer that is greater than or equal to the ``value``.
809
+ Returns a float value representing the smallest number that is greater than or equal to the ``value``.
810
+
811
+ Note
812
+ ----
813
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
814
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity.
798
815
 
799
816
  Parameters
800
817
  ----------
@@ -806,21 +823,113 @@ def ceil(value):
806
823
 
807
824
  Examples
808
825
  --------
809
- >>> data = otp.Ticks(A=[-1.7, -1.5, -1.2, -1, 0 , 1, 1.2, 1.5, 1.7])
826
+ >>> data = otp.Ticks(A=[-1.7, -1.5, -1.2, -1, 0 , 1, 1.2, 1.5, 1.7, -otp.inf, otp.inf, otp.nan])
810
827
  >>> data['CEIL'] = otp.math.ceil(data['A'])
811
828
  >>> otp.run(data)
812
- Time A CEIL
813
- 0 2003-12-01 00:00:00.000 -1.7 -1
814
- 1 2003-12-01 00:00:00.001 -1.5 -1
815
- 2 2003-12-01 00:00:00.002 -1.2 -1
816
- 3 2003-12-01 00:00:00.003 -1.0 -1
817
- 4 2003-12-01 00:00:00.004 0.0 0
818
- 5 2003-12-01 00:00:00.005 1.0 1
819
- 6 2003-12-01 00:00:00.006 1.2 2
820
- 7 2003-12-01 00:00:00.007 1.5 2
821
- 8 2003-12-01 00:00:00.008 1.7 2
822
- """
829
+ Time A CEIL
830
+ 0 2003-12-01 00:00:00.000 -1.7 -1.0
831
+ 1 2003-12-01 00:00:00.001 -1.5 -1.0
832
+ 2 2003-12-01 00:00:00.002 -1.2 -1.0
833
+ 3 2003-12-01 00:00:00.003 -1.0 -1.0
834
+ 4 2003-12-01 00:00:00.004 0.0 0.0
835
+ 5 2003-12-01 00:00:00.005 1.0 1.0
836
+ 6 2003-12-01 00:00:00.006 1.2 2.0
837
+ 7 2003-12-01 00:00:00.007 1.5 2.0
838
+ 8 2003-12-01 00:00:00.008 1.7 2.0
839
+ 9 2003-12-01 00:00:00.009 -inf -inf
840
+ 10 2003-12-01 00:00:00.010 inf inf
841
+ 11 2003-12-01 00:00:00.011 NaN NaN
842
+ """
843
+ def fun(v):
844
+ v = value2str(v)
845
+ return f'CASE({v}, NAN(), NAN(), INFINITY(), INFINITY(), -INFINITY(), -INFINITY(), CEIL({v}) * 1.0)', float
846
+
823
847
  return _Operation(
824
- op_func=lambda v: (f'CEIL({value2str(v)})', int),
848
+ op_func=fun,
825
849
  op_params=[value],
826
850
  )
851
+
852
+
853
+ def round(value, precision=0, rounding_method='upward'):
854
+ """
855
+ Rounds value with specified ``precision`` and ``rounding_method``.
856
+
857
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
858
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity.
859
+
860
+ Parameters
861
+ ----------
862
+ precision: int
863
+ Number from -12 to 12.
864
+ Positive precision is precision after the floating point.
865
+ Negative precision is precision before the floating point (and the fraction part is dropped in this case).
866
+ rounding_method: str
867
+ Used for values that are exactly half-way between two integers (when the fraction part of value is exactly 0.5).
868
+ Available values are **upward**, **downward**, **towards_zero**, **away_from_zero**.
869
+ Default is **upward**.
870
+
871
+ Examples
872
+ --------
873
+
874
+ Different rounding methods produce different results for values that are exactly half-way between two integers:
875
+
876
+ >>> t = otp.Ticks(A=[-123.45, 123.45, -123.4, 123.6])
877
+ >>> t['UPWARD'] = otp.math.round(t['A'], precision=1, rounding_method='upward')
878
+ >>> t['DOWNWARD'] = otp.math.round(t['A'], precision=1, rounding_method='downward')
879
+ >>> t['TOWARDS_ZERO'] = otp.math.round(t['A'], precision=1, rounding_method='towards_zero')
880
+ >>> t['AWAY_FROM_ZERO'] = otp.math.round(t['A'], precision=1, rounding_method='away_from_zero')
881
+ >>> otp.run(t).head(2)
882
+ Time A UPWARD DOWNWARD TOWARDS_ZERO AWAY_FROM_ZERO
883
+ 0 2003-12-01 00:00:00.000 -123.45 -123.4 -123.5 -123.4 -123.5
884
+ 1 2003-12-01 00:00:00.001 123.45 123.5 123.4 123.4 123.5
885
+
886
+ Note that for other cases all methods produce the same results:
887
+
888
+ >>> otp.run(t).tail(2)
889
+ Time A UPWARD DOWNWARD TOWARDS_ZERO AWAY_FROM_ZERO
890
+ 2 2003-12-01 00:00:00.002 -123.4 -123.4 -123.4 -123.4 -123.4
891
+ 3 2003-12-01 00:00:00.003 123.6 123.6 123.6 123.6 123.6
892
+
893
+ Positive precision truncates to the number of digits *after* floating point:
894
+
895
+ >>> t = otp.Ticks(A=[-123.45, 123.45])
896
+ >>> t['ROUND1'] = otp.math.round(t['A'], 1)
897
+ >>> t['ROUND2'] = otp.math.round(t['A'], 2)
898
+ >>> otp.run(t)
899
+ Time A ROUND1 ROUND2
900
+ 0 2003-12-01 00:00:00.000 -123.45 -123.4 -123.45
901
+ 1 2003-12-01 00:00:00.001 123.45 123.5 123.45
902
+
903
+ Negative precision truncates to the number of digits *before* floating point
904
+ (and the fraction part is dropped in this case):
905
+
906
+ >>> t = otp.Ticks(A=[-123.45, 123.45])
907
+ >>> t['ROUND_M1'] = otp.math.round(t['A'], -1)
908
+ >>> t['ROUND_M2'] = otp.math.round(t['A'], -2)
909
+ >>> otp.run(t)
910
+ Time A ROUND_M1 ROUND_M2
911
+ 0 2003-12-01 00:00:00.000 -123.45 -120.0 -100.0
912
+ 1 2003-12-01 00:00:00.001 123.45 120.0 100.0
913
+
914
+ Rounding :class:`otp.nan <onetick.py.nan>` returns NaN
915
+ and rounding :class:`otp.inf <onetick.py.inf>` returns Infinity in all cases:
916
+
917
+ >>> t = otp.Ticks(A=[otp.inf, -otp.inf, otp.nan])
918
+ >>> t['ROUND_0'] = otp.math.round(t['A'])
919
+ >>> t['ROUND_P2'] = otp.math.round(t['A'], 2)
920
+ >>> t['ROUND_M2'] = otp.math.round(t['A'], -2)
921
+ >>> otp.run(t)
922
+ Time A ROUND_0 ROUND_P2 ROUND_M2
923
+ 0 2003-12-01 00:00:00.000 inf inf inf inf
924
+ 1 2003-12-01 00:00:00.001 -inf -inf -inf -inf
925
+ 2 2003-12-01 00:00:00.002 NaN NaN NaN NaN
926
+ """
927
+ if not -12 <= precision <= 12:
928
+ raise ValueError("Parameter 'precision' must be an integer in range [-12, 12]")
929
+ supported_rounding_methods = {'upward', 'downward', 'towards_zero', 'away_from_zero'}
930
+ if rounding_method not in supported_rounding_methods:
931
+ raise ValueError(f"Parameter 'rounding_method' must be one of {supported_rounding_methods}")
932
+ return _Operation(
933
+ op_func=lambda v, p, r: (f'ROUND_DOUBLE({value2str(v)},{value2str(p)},{value2str(r)})', float),
934
+ op_params=[value, precision, rounding_method],
935
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onetick-py
3
- Version: 1.171.0
3
+ Version: 1.172.0
4
4
  Summary: Python package that allows you to work with OneTick
5
5
  Author-email: solutions <solutions@onetick.com>
6
6
  License-Expression: MIT
@@ -85,7 +85,7 @@ The latest version of ``onetick-py`` is available on PyPI: <https://pypi.org/pro
85
85
 
86
86
  pip install onetick-py[webapi]
87
87
 
88
- Use ``webapi`` extra to easily use it with remote OneTick Cloud server.
88
+ Use ``webapi`` extra to easily use it with remote OneTick REST Servers, such as [OneTick Cloud](https://www.onetick.com/cloud-services).
89
89
 
90
90
  See [Getting Started](https://docs.pip.distribution.sol.onetick.com/static/getting_started/root.html)
91
91
  section in the documentation to see how quickly set up ``onetick-py`` configuration
@@ -112,6 +112,8 @@ section in the documentation.
112
112
  - **Data Visualization**: Compatible with OneTick's visualization tool, OneTick Dashboard.
113
113
  - **Machine Learning**: Integrates with the OneTick ML library [onetick-ml](https://dsframework.pip.distribution.sol.onetick.com/intro.html).
114
114
  - **Industry Applications**: Industry leading OneTick's Trade Surveillance and BestEx/TCA solutions are written in ``onetick.py``.
115
+ - **Back Testing**: Retrieve historic market data and metrics.
116
+ - **Market Microstructure**: Consolidated Book Depth analysis.
115
117
 
116
118
  ## Advantages Over Competitors
117
119
 
@@ -13,15 +13,15 @@ onetick/lib/__init__.py,sha256=Rp7CIDoA4E6LIm1f2mNvl_5b_n-0U3suA3FmBXbmKoU,114
13
13
  onetick/lib/instance.py,sha256=3FJB8PWs2ap-EGb6DzsnLRL2meTMUViTdy343m6tHvM,4825
14
14
  onetick/py/__init__.py,sha256=Ge1Ekl6OHRjm5KrXojq3AzLCaUGvLNWuaIK0C9DdwWU,11164
15
15
  onetick/py/_stack_info.py,sha256=PHZOkW_fK7Fbl4YEj5CaYK9L6vh4j-bUU7_cSYOWZ30,2546
16
- onetick/py/_version.py,sha256=R6vgYKh_qtyxN49H_qTnzUglwwB5_XMe8UEeYU-DvfM,76
16
+ onetick/py/_version.py,sha256=7nbtSF9w76mnK4B_3vuXM8dDMY1zw1fS3UowT04mTiE,76
17
17
  onetick/py/backports.py,sha256=mR00mxe7E7UgBljf-Wa93Mo6lpi-C4Op561uhPUoEt8,815
18
18
  onetick/py/cache.py,sha256=BBZg8n0AGjZzZapg4752LkSZdX5C6DGf7vU9sAStv6A,12798
19
19
  onetick/py/compatibility.py,sha256=x-TXsOqPNb2gnARSDwyZba-1FE7bvuat2vrObRCSywo,30917
20
20
  onetick/py/configuration.py,sha256=cMUl6XNjO3qgpO5PmOplb2uFSAQtWPu7pIUNhhRpjL4,28408
21
- onetick/py/functions.py,sha256=LyLQ7NTNFzKfkR3A5RazS3tOtVqORe1BPrg6B4AAuLM,97689
21
+ onetick/py/functions.py,sha256=yJKL4thjNh_u-DKY08rCDMGJO_IMAeN2Odu70Q9U3Ew,97937
22
22
  onetick/py/license.py,sha256=50dsFrE-NKsPOdkAoyxHr44bH8DzFCr_6TabX0JH6tQ,6140
23
23
  onetick/py/log.py,sha256=Els2drZcVjJrD6kvbwgFGEpg6jAacoUEtyN6rCaauuk,2723
24
- onetick/py/math.py,sha256=LcbVcmW6GJHcjJJiPNZe5Mh5ZJBpdC8AxJMltMA1Apk,21357
24
+ onetick/py/math.py,sha256=MZvlyUjxOWGJvmxK8pfMkCr4THM52AE6NyGEidgDMyE,26311
25
25
  onetick/py/misc.py,sha256=mD-EJslLGjQ0ROEez76HvOY0tsX8_1bC1QOkyHY9FZ8,13934
26
26
  onetick/py/otq.py,sha256=VSdCrp3zTzNQHv9gM_xE4Al4ujBsio7uWk3SqU4eC4Y,8271
27
27
  onetick/py/pyomd_mock.py,sha256=A7IIUraN9yCsPhvnHXQUZrmwFjlh7vofSnYm4G7bdsc,2006
@@ -51,7 +51,7 @@ onetick/py/core/cut_builder.py,sha256=rj5aPJ25Dr5fsd9Dw1SO8k9kPGy0hV06anxFqBppFW
51
51
  onetick/py/core/db_constants.py,sha256=OqBbBKLECf8Bw8ylw30jc72xgCJ0gRIC-K-QkkbQ4LI,437
52
52
  onetick/py/core/eval_query.py,sha256=mcsOVlQ2vNSfZ-tRUB2z1gdiMJw4MpU2fK2hW-ua3e4,11528
53
53
  onetick/py/core/lambda_object.py,sha256=ayob_2c2XYSG7vFsqp-2b9FSPD-3TFReLbx3de3tkqE,16812
54
- onetick/py/core/multi_output_source.py,sha256=i9mxtM3yIF30hsVZ-6XttU407VmHklCdPjNDabgB374,7769
54
+ onetick/py/core/multi_output_source.py,sha256=f3dXr9kwmED77oWDFVr9cn44aYiJxC81loq2pX4u50Q,8766
55
55
  onetick/py/core/per_tick_script.py,sha256=I3pfidriS1TrFPc3DAABt91GKMgby9P_8KBatiFQx6U,83322
56
56
  onetick/py/core/query_inspector.py,sha256=Jwnw7qUVvjvaT63mQ5PkUSy8x36knoxWrNll3aXuLZw,16440
57
57
  onetick/py/core/source.py,sha256=AX4DUK1frV_FUCG5sywsn42xYX7Y2sYC7vMCOq6TeRg,63998
@@ -88,23 +88,23 @@ onetick/py/core/_source/source_methods/sorts.py,sha256=tDFt3rObNHP-S_HOtDd6SLpgk
88
88
  onetick/py/core/_source/source_methods/switches.py,sha256=pcnfT45QWn87qq1pWkvZbqeEoM7lrq8qNPxM8g9raxs,3846
89
89
  onetick/py/core/_source/source_methods/symbols.py,sha256=MG0dgVVVJ6fD_-GJkkXEgTeAsfS79ymJWmuKSL-0QSs,3968
90
90
  onetick/py/core/_source/source_methods/times.py,sha256=2kbLHG-3RQM6uWmw8pBGDiAz4R83KK46Tp1smTY6SR8,27665
91
- onetick/py/core/_source/source_methods/writes.py,sha256=W00hAJtQ0phPv5vzS08rSj_N0-ofhih39DalpR8RntQ,42129
91
+ onetick/py/core/_source/source_methods/writes.py,sha256=fPUbiqlm30Kb4QzXZLtWCsQiTFBDxK5oOWuVyfVXbYM,42717
92
92
  onetick/py/core/column_operations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
93
- onetick/py/core/column_operations/base.py,sha256=ihNaKhhDFk7-v-wpXE11Wqy0WAqEGI1OC2PG4POK1mc,33203
93
+ onetick/py/core/column_operations/base.py,sha256=Kcwfd4PErCGLSbkqtFKY6SZL1-pksWHB-Pc-5A8I3WM,36135
94
94
  onetick/py/core/column_operations/_methods/__init__.py,sha256=_C5hpQG51MingtWW2N8vYzSVFpR314xIrtukBfEfPMk,207
95
95
  onetick/py/core/column_operations/_methods/_internal.py,sha256=M04DbbD9DjA3NrrbibuQPje8ylkaYnVB5Nmlwx1RvaE,878
96
96
  onetick/py/core/column_operations/_methods/conversions.py,sha256=QB8ZKJi5qlV8ydPn43nRHa3HMkaXCDV2Fkrq2gnVQ6U,7001
97
- onetick/py/core/column_operations/_methods/methods.py,sha256=-zl2gg7rGtsbxnfoSoMIvg3Pjanxwlijrd1RJflu3Nw,11157
97
+ onetick/py/core/column_operations/_methods/methods.py,sha256=OaXiDcdPYXnPlWhwD-BCac5UAecZFnEKCkxBpQOVB5E,11054
98
98
  onetick/py/core/column_operations/_methods/op_types.py,sha256=rUMrtIPCp7TYYJIK4f836KxZIcvW60MYv3cYTGMpfRA,5004
99
99
  onetick/py/core/column_operations/accessors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
100
- onetick/py/core/column_operations/accessors/_accessor.py,sha256=GJtqxDNzve6TM8ESJp0gzhSqfKPUYA7_vvLKFO1_rAA,1001
101
- onetick/py/core/column_operations/accessors/decimal_accessor.py,sha256=7B-h932PhUmUV3flAAvPpKeVR7BbaESwSPyBTkxdxoI,2930
102
- onetick/py/core/column_operations/accessors/dt_accessor.py,sha256=RvgIuCXs3nMXTNqJvP0Iqu7i_vUoUDgrG7QvfnrKvRs,16837
103
- onetick/py/core/column_operations/accessors/float_accessor.py,sha256=6di5Pw0nLwKEqnzQImzQ9ORv45xGm-uevFGCg-FZz4w,5541
104
- onetick/py/core/column_operations/accessors/str_accessor.py,sha256=65WdZQWayVy8HEh7xn5M3j08AO_fTJ5vSU8CyxNmOrY,55519
100
+ onetick/py/core/column_operations/accessors/_accessor.py,sha256=b5K4OQmnO4NeFK1QsKjgZ1WfEyBjxKWMkb12RBbnGXQ,983
101
+ onetick/py/core/column_operations/accessors/decimal_accessor.py,sha256=DwgJ-as0p_gex6UGxhxhsn9chSpne5YV-t1ntvr-saw,3345
102
+ onetick/py/core/column_operations/accessors/dt_accessor.py,sha256=UeY7UNUiaLdrX0S68SuEk7gXASGCjJoRdTq0pm30ktQ,18616
103
+ onetick/py/core/column_operations/accessors/float_accessor.py,sha256=IjZNrUzdT_u1szJFOI5ivExbvzC5KwiHwz6CFMMZRo0,5994
104
+ onetick/py/core/column_operations/accessors/str_accessor.py,sha256=kpCQQQJd02yWsTVwkAMYBfJMTePSffzDiT-6utRqNB4,55248
105
105
  onetick/py/db/__init__.py,sha256=-TKRO0suXTR-mLAppYt-Vegu9HQn7LU_JcObXpS3N9M,61
106
106
  onetick/py/db/_inspection.py,sha256=oBd5XAk2RGHad7KpS62Ftwlmqx96EUxIFYCbZ-Qyt94,48288
107
- onetick/py/db/db.py,sha256=nlkwQ0cDo2T7am4stNbbP_5NVDWD-nOIcoWYFVzr-_w,55920
107
+ onetick/py/db/db.py,sha256=3K1X9RQ2ObXGxyxSi-jSSl6b7p0OuGZJJkx9SGzkBsc,55930
108
108
  onetick/py/db/utils.py,sha256=gt-KmbGgcp1tH81LH-cLO08n2Hx8GaBPbvfEN22mgLg,2309
109
109
  onetick/py/docs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
110
110
  onetick/py/docs/docstring_parser.py,sha256=j38L1jO1JFAzYqR1F5hilIzcIjOWILqNQSB25Fd2hhM,3695
@@ -144,9 +144,9 @@ onetick/py/utils/script.py,sha256=Y8NujEo2_5QaP6KDnLKJiKQ7SmMjw8_dv8sYL9rHDCE,11
144
144
  onetick/py/utils/temp.py,sha256=j-BC155dE46k0zfKTTs26KTF0CK6WA1hO2GD54iunyM,17380
145
145
  onetick/py/utils/types.py,sha256=_tYf66r9JVgjtiCJfxIxrg_BQEjHkjlnck_i86dBYEY,3606
146
146
  onetick/py/utils/tz.py,sha256=QXclESLGU8YXysUT9DXkcBqLWWO47Bb_tanFUzYpPZI,2800
147
- onetick_py-1.171.0.dist-info/licenses/LICENSE,sha256=Yhu7lKNFS0fsaN-jSattEMRtCOPueP58Eu5BPH8ZGjM,1075
148
- onetick_py-1.171.0.dist-info/METADATA,sha256=xbh4fMhGnAy3uBraumRUWLE9ynOdvCc-sWefGxlcCjg,8024
149
- onetick_py-1.171.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
150
- onetick_py-1.171.0.dist-info/entry_points.txt,sha256=QmK_tFswIN-SQRmtnTSBEi8GvT0TVq-66IzXXZIsV3U,81
151
- onetick_py-1.171.0.dist-info/top_level.txt,sha256=Na1jSJmVMyYGOndaswt554QKIUwQjcYh6th2ATsmw0U,23
152
- onetick_py-1.171.0.dist-info/RECORD,,
147
+ onetick_py-1.172.0.dist-info/licenses/LICENSE,sha256=Yhu7lKNFS0fsaN-jSattEMRtCOPueP58Eu5BPH8ZGjM,1075
148
+ onetick_py-1.172.0.dist-info/METADATA,sha256=NOHCPlqgp-lzXlGekA1oDazmitCNBSoDrhnqlgkjOrg,8216
149
+ onetick_py-1.172.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
150
+ onetick_py-1.172.0.dist-info/entry_points.txt,sha256=QmK_tFswIN-SQRmtnTSBEi8GvT0TVq-66IzXXZIsV3U,81
151
+ onetick_py-1.172.0.dist-info/top_level.txt,sha256=Na1jSJmVMyYGOndaswt554QKIUwQjcYh6th2ATsmw0U,23
152
+ onetick_py-1.172.0.dist-info/RECORD,,