onetick-py 1.177.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.
Files changed (152) hide show
  1. locator_parser/__init__.py +0 -0
  2. locator_parser/acl.py +73 -0
  3. locator_parser/actions.py +262 -0
  4. locator_parser/common.py +368 -0
  5. locator_parser/io.py +43 -0
  6. locator_parser/locator.py +150 -0
  7. onetick/__init__.py +101 -0
  8. onetick/doc_utilities/__init__.py +3 -0
  9. onetick/doc_utilities/napoleon.py +40 -0
  10. onetick/doc_utilities/ot_doctest.py +140 -0
  11. onetick/doc_utilities/snippets.py +279 -0
  12. onetick/lib/__init__.py +4 -0
  13. onetick/lib/instance.py +141 -0
  14. onetick/py/__init__.py +293 -0
  15. onetick/py/_stack_info.py +89 -0
  16. onetick/py/_version.py +2 -0
  17. onetick/py/aggregations/__init__.py +11 -0
  18. onetick/py/aggregations/_base.py +648 -0
  19. onetick/py/aggregations/_docs.py +948 -0
  20. onetick/py/aggregations/compute.py +286 -0
  21. onetick/py/aggregations/functions.py +2216 -0
  22. onetick/py/aggregations/generic.py +104 -0
  23. onetick/py/aggregations/high_low.py +80 -0
  24. onetick/py/aggregations/num_distinct.py +83 -0
  25. onetick/py/aggregations/order_book.py +501 -0
  26. onetick/py/aggregations/other.py +1014 -0
  27. onetick/py/backports.py +26 -0
  28. onetick/py/cache.py +374 -0
  29. onetick/py/callback/__init__.py +5 -0
  30. onetick/py/callback/callback.py +276 -0
  31. onetick/py/callback/callbacks.py +131 -0
  32. onetick/py/compatibility.py +798 -0
  33. onetick/py/configuration.py +771 -0
  34. onetick/py/core/__init__.py +0 -0
  35. onetick/py/core/_csv_inspector.py +93 -0
  36. onetick/py/core/_internal/__init__.py +0 -0
  37. onetick/py/core/_internal/_manually_bound_value.py +6 -0
  38. onetick/py/core/_internal/_nodes_history.py +250 -0
  39. onetick/py/core/_internal/_op_utils/__init__.py +0 -0
  40. onetick/py/core/_internal/_op_utils/every_operand.py +9 -0
  41. onetick/py/core/_internal/_op_utils/is_const.py +10 -0
  42. onetick/py/core/_internal/_per_tick_scripts/tick_list_sort_template.script +121 -0
  43. onetick/py/core/_internal/_proxy_node.py +140 -0
  44. onetick/py/core/_internal/_state_objects.py +2312 -0
  45. onetick/py/core/_internal/_state_vars.py +93 -0
  46. onetick/py/core/_source/__init__.py +0 -0
  47. onetick/py/core/_source/_symbol_param.py +95 -0
  48. onetick/py/core/_source/schema.py +97 -0
  49. onetick/py/core/_source/source_methods/__init__.py +0 -0
  50. onetick/py/core/_source/source_methods/aggregations.py +809 -0
  51. onetick/py/core/_source/source_methods/applyers.py +296 -0
  52. onetick/py/core/_source/source_methods/columns.py +141 -0
  53. onetick/py/core/_source/source_methods/data_quality.py +301 -0
  54. onetick/py/core/_source/source_methods/debugs.py +272 -0
  55. onetick/py/core/_source/source_methods/drops.py +120 -0
  56. onetick/py/core/_source/source_methods/fields.py +619 -0
  57. onetick/py/core/_source/source_methods/filters.py +1002 -0
  58. onetick/py/core/_source/source_methods/joins.py +1413 -0
  59. onetick/py/core/_source/source_methods/merges.py +605 -0
  60. onetick/py/core/_source/source_methods/misc.py +1455 -0
  61. onetick/py/core/_source/source_methods/pandases.py +155 -0
  62. onetick/py/core/_source/source_methods/renames.py +356 -0
  63. onetick/py/core/_source/source_methods/sorts.py +183 -0
  64. onetick/py/core/_source/source_methods/switches.py +142 -0
  65. onetick/py/core/_source/source_methods/symbols.py +117 -0
  66. onetick/py/core/_source/source_methods/times.py +627 -0
  67. onetick/py/core/_source/source_methods/writes.py +986 -0
  68. onetick/py/core/_source/symbol.py +205 -0
  69. onetick/py/core/_source/tmp_otq.py +222 -0
  70. onetick/py/core/column.py +209 -0
  71. onetick/py/core/column_operations/__init__.py +0 -0
  72. onetick/py/core/column_operations/_methods/__init__.py +4 -0
  73. onetick/py/core/column_operations/_methods/_internal.py +28 -0
  74. onetick/py/core/column_operations/_methods/conversions.py +216 -0
  75. onetick/py/core/column_operations/_methods/methods.py +292 -0
  76. onetick/py/core/column_operations/_methods/op_types.py +160 -0
  77. onetick/py/core/column_operations/accessors/__init__.py +0 -0
  78. onetick/py/core/column_operations/accessors/_accessor.py +28 -0
  79. onetick/py/core/column_operations/accessors/decimal_accessor.py +104 -0
  80. onetick/py/core/column_operations/accessors/dt_accessor.py +537 -0
  81. onetick/py/core/column_operations/accessors/float_accessor.py +184 -0
  82. onetick/py/core/column_operations/accessors/str_accessor.py +1367 -0
  83. onetick/py/core/column_operations/base.py +1121 -0
  84. onetick/py/core/cut_builder.py +150 -0
  85. onetick/py/core/db_constants.py +20 -0
  86. onetick/py/core/eval_query.py +245 -0
  87. onetick/py/core/lambda_object.py +441 -0
  88. onetick/py/core/multi_output_source.py +232 -0
  89. onetick/py/core/per_tick_script.py +2256 -0
  90. onetick/py/core/query_inspector.py +464 -0
  91. onetick/py/core/source.py +1744 -0
  92. onetick/py/db/__init__.py +2 -0
  93. onetick/py/db/_inspection.py +1128 -0
  94. onetick/py/db/db.py +1327 -0
  95. onetick/py/db/utils.py +64 -0
  96. onetick/py/docs/__init__.py +0 -0
  97. onetick/py/docs/docstring_parser.py +112 -0
  98. onetick/py/docs/utils.py +81 -0
  99. onetick/py/functions.py +2398 -0
  100. onetick/py/license.py +190 -0
  101. onetick/py/log.py +88 -0
  102. onetick/py/math.py +935 -0
  103. onetick/py/misc.py +470 -0
  104. onetick/py/oqd/__init__.py +22 -0
  105. onetick/py/oqd/eps.py +1195 -0
  106. onetick/py/oqd/sources.py +325 -0
  107. onetick/py/otq.py +216 -0
  108. onetick/py/pyomd_mock.py +47 -0
  109. onetick/py/run.py +916 -0
  110. onetick/py/servers.py +173 -0
  111. onetick/py/session.py +1347 -0
  112. onetick/py/sources/__init__.py +19 -0
  113. onetick/py/sources/cache.py +167 -0
  114. onetick/py/sources/common.py +128 -0
  115. onetick/py/sources/csv.py +642 -0
  116. onetick/py/sources/custom.py +85 -0
  117. onetick/py/sources/data_file.py +305 -0
  118. onetick/py/sources/data_source.py +1045 -0
  119. onetick/py/sources/empty.py +94 -0
  120. onetick/py/sources/odbc.py +337 -0
  121. onetick/py/sources/order_book.py +271 -0
  122. onetick/py/sources/parquet.py +168 -0
  123. onetick/py/sources/pit.py +191 -0
  124. onetick/py/sources/query.py +495 -0
  125. onetick/py/sources/snapshots.py +419 -0
  126. onetick/py/sources/split_query_output_by_symbol.py +198 -0
  127. onetick/py/sources/symbology_mapping.py +123 -0
  128. onetick/py/sources/symbols.py +374 -0
  129. onetick/py/sources/ticks.py +825 -0
  130. onetick/py/sql.py +70 -0
  131. onetick/py/state.py +251 -0
  132. onetick/py/types.py +2131 -0
  133. onetick/py/utils/__init__.py +70 -0
  134. onetick/py/utils/acl.py +93 -0
  135. onetick/py/utils/config.py +186 -0
  136. onetick/py/utils/default.py +49 -0
  137. onetick/py/utils/file.py +38 -0
  138. onetick/py/utils/helpers.py +76 -0
  139. onetick/py/utils/locator.py +94 -0
  140. onetick/py/utils/perf.py +498 -0
  141. onetick/py/utils/query.py +49 -0
  142. onetick/py/utils/render.py +1374 -0
  143. onetick/py/utils/script.py +244 -0
  144. onetick/py/utils/temp.py +471 -0
  145. onetick/py/utils/types.py +120 -0
  146. onetick/py/utils/tz.py +84 -0
  147. onetick_py-1.177.0.dist-info/METADATA +137 -0
  148. onetick_py-1.177.0.dist-info/RECORD +152 -0
  149. onetick_py-1.177.0.dist-info/WHEEL +5 -0
  150. onetick_py-1.177.0.dist-info/entry_points.txt +2 -0
  151. onetick_py-1.177.0.dist-info/licenses/LICENSE +21 -0
  152. onetick_py-1.177.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,104 @@
1
+ from onetick.py import types as ott
2
+ from onetick.py.core.column_operations.accessors._accessor import _Accessor
3
+ from onetick.py.core.column_operations.base import _Operation
4
+
5
+
6
+ class _DecimalAccessor(_Accessor):
7
+ """
8
+ Accessor for decimal functions
9
+
10
+ >>> data = otp.Ticks(X=[otp.decimal(1.1), otp.decimal(1.2)])
11
+ >>> data["Y"] = data["X"].decimal.<function_name>() # doctest: +SKIP
12
+ """
13
+
14
+ def str(self, precision=8):
15
+ """
16
+ Converts decimal to str.
17
+
18
+ Parameters
19
+ ----------
20
+ precision: Operation or int
21
+ Number of digits after floating point.
22
+
23
+ Returns
24
+ -------
25
+ result: Operation
26
+ String representation of decimal value.
27
+
28
+ Examples
29
+ --------
30
+
31
+ >>> data = otp.Ticks(X=[otp.decimal(1), otp.decimal(2.17), otp.decimal(10.31861), otp.decimal(3.141593)])
32
+ >>> data['X'] = data['X'].decimal.str(precision=3)
33
+ >>> data = otp.run(data)
34
+ >>> data['X']
35
+ 0 1.000
36
+ 1 2.170
37
+ 2 10.319
38
+ 3 3.142
39
+ Name: X, dtype: object
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
+
47
+ return _DecimalAccessor.Formatter(
48
+ op_params=[self._base_column, precision],
49
+ dtype=str,
50
+ formatter=formatter,
51
+ )
52
+
53
+ def cmp(self, other, eps):
54
+ """
55
+ Compare two decimal values according to ``eps`` relative difference.
56
+
57
+ This function returns 0 if column = other, 1 if column > other, and -1 if column < other.
58
+ Two numbers are considered to be equal if both of them are NaN or
59
+ ``abs(column - other) / (abs(column) + abs(other)) < eps``.
60
+ In other words, ``eps`` represents a relative difference (percentage) between the two numbers,
61
+ not an absolute difference.
62
+
63
+ Parameters
64
+ ----------
65
+ other: Operation or decimal
66
+ column or value to compare with
67
+ eps: Operation or decimal
68
+ column or value with relative difference
69
+
70
+ Returns
71
+ -------
72
+ result: Operation
73
+ 0 if column == other, 1 if column > other, and -1 if column < other.
74
+
75
+ Examples
76
+ --------
77
+
78
+ >>> data = otp.Ticks(
79
+ ... X=[otp.decimal(1), otp.decimal(2.17), otp.decimal(10.31841), otp.decimal(3.141593), otp.decimal(6)],
80
+ ... OTHER=[otp.decimal(1.01), otp.decimal(2.1), otp.decimal(10.32841), otp.decimal(3.14), otp.decimal(5)],
81
+ ... EPS=[0, 1, 0.1, 0.001, 0.001]
82
+ ... )
83
+ >>> data['X'] = data['X'].decimal.cmp(data['OTHER'], data['EPS'])
84
+ >>> data = otp.run(data)
85
+ >>> data['X']
86
+ 0 -1.0
87
+ 1 0.0
88
+ 2 0.0
89
+ 3 0.0
90
+ 4 1.0
91
+ Name: X, dtype: float64
92
+ """
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
+
100
+ return _DecimalAccessor.Formatter(
101
+ op_params=[self._base_column, other, eps],
102
+ dtype=ott.decimal,
103
+ formatter=formatter,
104
+ )
@@ -0,0 +1,537 @@
1
+ from typing import Union
2
+
3
+ from onetick.py import configuration, utils
4
+ from onetick.py import types as ott
5
+ from onetick.py.core.column_operations.accessors._accessor import _Accessor
6
+ from onetick.py.backports import Literal
7
+ from onetick.py.types import datetime, value2str
8
+ from onetick.py.docs.utils import docstring, param_doc
9
+ from onetick.py.core.column import _Column
10
+ from onetick.py.core.column_operations.base import _Operation
11
+
12
+
13
+ _timezone_doc = param_doc(
14
+ name='timezone',
15
+ str_annotation='str | Operation | Column',
16
+ desc="""
17
+ Name of the timezone, an operation or a column with it.
18
+ By default, the timezone of the query will be used.
19
+ """,
20
+ annotation=Union[str, _Operation, _Column]
21
+ )
22
+
23
+
24
+ class _DtAccessor(_Accessor):
25
+
26
+ """
27
+ Accessor for datetime functions
28
+
29
+ >>> data = otp.Ticks(X=[otp.dt(2019, 1, 1, 1, 1, 1), otp.dt(2019, 2, 2, 2, 2, 2)])
30
+ >>> data["Y"] = data["X"].dt.<function_name>() # doctest: +SKIP
31
+ """
32
+
33
+ @docstring(parameters=[_timezone_doc], add_self=True)
34
+ def strftime(self, format='%Y/%m/%d %H:%M:%S.%J', timezone=None):
35
+ """
36
+ Converts the number of nanoseconds (datetime) since 1970/01/01 GMT into
37
+ the string specified by ``format`` for a specified ``timezone``.
38
+
39
+ Parameters
40
+ ----------
41
+ format: str
42
+ The format might contain any characters, but the following combinations of
43
+ characters have special meanings
44
+
45
+ %Y - Year (4 digits)
46
+
47
+ %y - Year (2 digits)
48
+
49
+ %m - Month (2 digits)
50
+
51
+ %d - Day of month (2 digits)
52
+
53
+ %H - Hours (2 digits, 24-hour format)
54
+
55
+ %I - Hours (2 digits, 12-hour format)
56
+
57
+ %M - Minutes (2 digits)
58
+
59
+ %S - Seconds (2 digits)
60
+
61
+ %q - Milliseconds (3 digits)
62
+
63
+ %J - Nanoseconds (9 digits)
64
+
65
+ %p - AM/PM (2 characters)
66
+
67
+ %% - % character
68
+
69
+ Examples
70
+ --------
71
+ >>> t = otp.Ticks(A=[otp.dt(2019, 1, 1, 1, 1, 1), otp.dt(2019, 2, 2, 2, 2, 2)])
72
+ >>> t['B'] = t['A'].dt.strftime('%d.%m.%Y')
73
+ >>> otp.run(t)[['A', 'B']]
74
+ A B
75
+ 0 2019-01-01 01:01:01 01.01.2019
76
+ 1 2019-02-02 02:02:02 02.02.2019
77
+ """
78
+ if timezone is utils.default:
79
+ timezone = configuration.config.tz
80
+
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})'
85
+
86
+ return _DtAccessor.Formatter(
87
+ op_params=[self._base_column, format, timezone],
88
+ dtype=str,
89
+ formatter=formatter,
90
+ )
91
+
92
+ def date(self):
93
+ """
94
+ Return a new :py:class:`onetick.py.nsectime` type operation filled with date only.
95
+
96
+ Examples
97
+ --------
98
+ >>> data = otp.Ticks(X=[otp.dt(2019, 1, 1, 1, 1, 1), otp.dt(2019, 2, 2, 2, 2, 2)])
99
+ >>> data["X"] = data["X"].dt.date() # OTdirective: snippet-name: timestamp operations.date;
100
+ >>> df = otp.run(data, timezone="GMT")
101
+ >>> df["X"]
102
+ 0 2019-01-01
103
+ 1 2019-02-02
104
+ Name: X, dtype: datetime64[ns]
105
+ """
106
+ format_str = "%Y%m%d"
107
+ return self.strftime(format_str, None).str.to_datetime(format_str, None)
108
+
109
+ @docstring(parameters=[_timezone_doc], add_self=True)
110
+ def day_of_week(
111
+ self, start_index: Union[int, _Operation] = 1, start_day: Literal['monday', 'sunday'] = 'monday', timezone=None,
112
+ ):
113
+ """
114
+ Return the day of the week.
115
+
116
+ Assuming the week starts on ``start_day``, which is denoted by ``start_index``.
117
+ Default: Monday - 1, ..., Sunday - 7; set according to ISO8601
118
+
119
+ Parameters
120
+ ----------
121
+ start_index: int or Operation
122
+ Sunday index.
123
+ start_day: 'monday' or 'sunday'
124
+ Day that will be denoted with ``start_index``
125
+
126
+ Examples
127
+ --------
128
+ >>> data = otp.Ticks(X=[otp.dt(2022, 5, i) for i in range(10, 17)])
129
+ >>> data['DAY_OF_WEEK'] = data['X'].dt.day_of_week()
130
+ >>> otp.run(data)[['X', 'DAY_OF_WEEK']]
131
+ X DAY_OF_WEEK
132
+ 0 2022-05-10 2
133
+ 1 2022-05-11 3
134
+ 2 2022-05-12 4
135
+ 3 2022-05-13 5
136
+ 4 2022-05-14 6
137
+ 5 2022-05-15 7
138
+ 6 2022-05-16 1
139
+ """
140
+
141
+ if start_day not in ['monday', 'sunday']:
142
+ raise ValueError(f"'start_day' parameter ({start_day}) not in ['monday', 'sunday']")
143
+
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':
150
+ # CASE should be uppercased because it can be used in per-tick script
151
+ format_ = f'CASE({format_}, 0, 7, {format_})-1'
152
+ format_ += f'+{_start_index}'
153
+ return format_
154
+
155
+ return _DtAccessor.Formatter(
156
+ op_params=[self._base_column, start_index, start_day, timezone],
157
+ dtype=int,
158
+ formatter=formatter,
159
+ )
160
+
161
+ @docstring(parameters=[_timezone_doc], add_self=True)
162
+ def day_name(self, timezone=None):
163
+ """
164
+ Returns the name of the weekday.
165
+
166
+ Examples
167
+ --------
168
+ >>> data = otp.Ticks(X=[otp.dt(2022, 5, i) for i in range(10, 17)])
169
+ >>> data['DAY_NAME'] = data['X'].dt.day_name()
170
+ >>> otp.run(data)[['X', 'DAY_NAME']]
171
+ X DAY_NAME
172
+ 0 2022-05-10 Tuesday
173
+ 1 2022-05-11 Wednesday
174
+ 2 2022-05-12 Thursday
175
+ 3 2022-05-13 Friday
176
+ 4 2022-05-14 Saturday
177
+ 5 2022-05-15 Sunday
178
+ 6 2022-05-16 Monday
179
+ """
180
+ def formatter(column, _timezone):
181
+ column = ott.value2str(column)
182
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
183
+ return f'DAYNAME({column},{_timezone})'
184
+
185
+ return _DtAccessor.Formatter(
186
+ op_params=[self._base_column, timezone],
187
+ dtype=str,
188
+ formatter=formatter,
189
+ )
190
+
191
+ @docstring(parameters=[_timezone_doc], add_self=True)
192
+ def day_of_month(self, timezone=None):
193
+ """
194
+ Return the day of the month.
195
+
196
+ Examples
197
+ --------
198
+ >>> data = otp.Ticks(X=[otp.dt(2022, 5, i) for i in range(10, 17)])
199
+ >>> data['DAY_OF_MONTH'] = data['X'].dt.day_of_month()
200
+ >>> otp.run(data)[['X', 'DAY_OF_MONTH']]
201
+ X DAY_OF_MONTH
202
+ 0 2022-05-10 10
203
+ 1 2022-05-11 11
204
+ 2 2022-05-12 12
205
+ 3 2022-05-13 13
206
+ 4 2022-05-14 14
207
+ 5 2022-05-15 15
208
+ 6 2022-05-16 16
209
+ """
210
+ def formatter(column, _timezone):
211
+ column = ott.value2str(column)
212
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
213
+ return f'DAYOFMONTH({column},{_timezone})'
214
+
215
+ return _DtAccessor.Formatter(
216
+ op_params=[self._base_column, timezone],
217
+ dtype=int,
218
+ formatter=formatter,
219
+ )
220
+
221
+ @docstring(parameters=[_timezone_doc], add_self=True)
222
+ def day_of_year(self, timezone=None):
223
+ """
224
+ Return the day of the year.
225
+
226
+ Examples
227
+ --------
228
+ >>> data = otp.Ticks(X=[otp.dt(2022, 5, i) for i in range(10, 17)])
229
+ >>> data['DAY_OF_YEAR'] = data['X'].dt.day_of_year()
230
+ >>> otp.run(data)[['X', 'DAY_OF_YEAR']]
231
+ X DAY_OF_YEAR
232
+ 0 2022-05-10 130
233
+ 1 2022-05-11 131
234
+ 2 2022-05-12 132
235
+ 3 2022-05-13 133
236
+ 4 2022-05-14 134
237
+ 5 2022-05-15 135
238
+ 6 2022-05-16 136
239
+ """
240
+ def formatter(column, _timezone):
241
+ column = ott.value2str(column)
242
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
243
+ return f'DAYOFYEAR({column},{_timezone})'
244
+
245
+ return _DtAccessor.Formatter(
246
+ op_params=[self._base_column, timezone],
247
+ dtype=int,
248
+ formatter=formatter,
249
+ )
250
+
251
+ @docstring(parameters=[_timezone_doc], add_self=True)
252
+ def hour(self, timezone=None):
253
+ """
254
+ Return the hour.
255
+
256
+ Examples
257
+ --------
258
+ >>> data = otp.Ticks(X=[otp.dt(2022, 5, 1, i, 0, 6) for i in range(10, 17)])
259
+ >>> data['HOUR'] = data['X'].dt.hour()
260
+ >>> otp.run(data)[['X', 'HOUR']]
261
+ X HOUR
262
+ 0 2022-05-01 10:00:06 10
263
+ 1 2022-05-01 11:00:06 11
264
+ 2 2022-05-01 12:00:06 12
265
+ 3 2022-05-01 13:00:06 13
266
+ 4 2022-05-01 14:00:06 14
267
+ 5 2022-05-01 15:00:06 15
268
+ 6 2022-05-01 16:00:06 16
269
+ """
270
+ def formatter(column, _timezone):
271
+ column = ott.value2str(column)
272
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
273
+ return f'HOUR({column},{_timezone})'
274
+
275
+ return _DtAccessor.Formatter(
276
+ op_params=[self._base_column, timezone],
277
+ dtype=int,
278
+ formatter=formatter,
279
+ )
280
+
281
+ @docstring(parameters=[_timezone_doc], add_self=True)
282
+ def minute(self, timezone=None):
283
+ """
284
+ Return the minute.
285
+
286
+
287
+ Examples
288
+ --------
289
+ >>> data = otp.Ticks(X=[otp.dt(2022, 5, 1, 15, i, 6) for i in range(10, 17)])
290
+ >>> data['MINUTE'] = data['X'].dt.minute()
291
+ >>> otp.run(data)[['X', 'MINUTE']]
292
+ X MINUTE
293
+ 0 2022-05-01 15:10:06 10
294
+ 1 2022-05-01 15:11:06 11
295
+ 2 2022-05-01 15:12:06 12
296
+ 3 2022-05-01 15:13:06 13
297
+ 4 2022-05-01 15:14:06 14
298
+ 5 2022-05-01 15:15:06 15
299
+ 6 2022-05-01 15:16:06 16
300
+ """
301
+ def formatter(column, _timezone):
302
+ column = ott.value2str(column)
303
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
304
+ return f'MINUTE({column},{_timezone})'
305
+
306
+ return _DtAccessor.Formatter(
307
+ op_params=[self._base_column, timezone],
308
+ dtype=int,
309
+ formatter=formatter,
310
+ )
311
+
312
+ @docstring(parameters=[_timezone_doc], add_self=True)
313
+ def second(self, timezone=None):
314
+ """
315
+ Return the second.
316
+
317
+ Examples
318
+ --------
319
+ >>> data = otp.Ticks(X=[otp.dt(2022, 5, 1, 15, 11, i) for i in range(10, 17)])
320
+ >>> data['SECOND'] = data['X'].dt.second()
321
+ >>> otp.run(data)[['X', 'SECOND']]
322
+ X SECOND
323
+ 0 2022-05-01 15:11:10 10
324
+ 1 2022-05-01 15:11:11 11
325
+ 2 2022-05-01 15:11:12 12
326
+ 3 2022-05-01 15:11:13 13
327
+ 4 2022-05-01 15:11:14 14
328
+ 5 2022-05-01 15:11:15 15
329
+ 6 2022-05-01 15:11:16 16
330
+ """
331
+ def formatter(column, _timezone):
332
+ column = ott.value2str(column)
333
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
334
+ return f'SECOND({column},{_timezone})'
335
+
336
+ return _DtAccessor.Formatter(
337
+ op_params=[self._base_column, timezone],
338
+ dtype=int,
339
+ formatter=formatter,
340
+ )
341
+
342
+ @docstring(parameters=[_timezone_doc], add_self=True)
343
+ def month(self, timezone=None):
344
+ """
345
+ Return the month.
346
+
347
+ Examples
348
+ --------
349
+ >>> data = otp.Ticks(X=[otp.dt(2022, i, 1) for i in range(3, 11)])
350
+ >>> data['MONTH'] = data['X'].dt.month()
351
+ >>> otp.run(data)[['X', 'MONTH']]
352
+ X MONTH
353
+ 0 2022-03-01 3
354
+ 1 2022-04-01 4
355
+ 2 2022-05-01 5
356
+ 3 2022-06-01 6
357
+ 4 2022-07-01 7
358
+ 5 2022-08-01 8
359
+ 6 2022-09-01 9
360
+ 7 2022-10-01 10
361
+ """
362
+ def formatter(column, _timezone):
363
+ column = ott.value2str(column)
364
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
365
+ return f'MONTH({column},{_timezone})'
366
+
367
+ return _DtAccessor.Formatter(
368
+ op_params=[self._base_column, timezone],
369
+ dtype=int,
370
+ formatter=formatter,
371
+ )
372
+
373
+ @docstring(parameters=[_timezone_doc], add_self=True)
374
+ def month_name(self, timezone=None):
375
+ """
376
+ Return name of the month.
377
+
378
+ Examples
379
+ --------
380
+ >>> data = otp.Ticks(X=[otp.dt(2022, i, 1) for i in range(3, 11)])
381
+ >>> data['MONTH_NAME'] = data['X'].dt.month_name()
382
+ >>> otp.run(data)[['X', 'MONTH_NAME']]
383
+ X MONTH_NAME
384
+ 0 2022-03-01 Mar
385
+ 1 2022-04-01 Apr
386
+ 2 2022-05-01 May
387
+ 3 2022-06-01 Jun
388
+ 4 2022-07-01 Jul
389
+ 5 2022-08-01 Aug
390
+ 6 2022-09-01 Sep
391
+ 7 2022-10-01 Oct
392
+ """
393
+ def formatter(column, _timezone):
394
+ column = ott.value2str(column)
395
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
396
+ return f'MONTHNAME({column},{_timezone})'
397
+
398
+ return _DtAccessor.Formatter(
399
+ op_params=[self._base_column, timezone],
400
+ dtype=str,
401
+ formatter=formatter,
402
+ )
403
+
404
+ @docstring(parameters=[_timezone_doc], add_self=True)
405
+ def quarter(self, timezone=None):
406
+ """
407
+ Return the quarter.
408
+
409
+ Examples
410
+ --------
411
+ >>> data = otp.Ticks(X=[otp.dt(2022, i, 1) for i in range(3, 11)])
412
+ >>> data['QUARTER'] = data['X'].dt.quarter()
413
+ >>> otp.run(data)[['X', 'QUARTER']]
414
+ X QUARTER
415
+ 0 2022-03-01 1
416
+ 1 2022-04-01 2
417
+ 2 2022-05-01 2
418
+ 3 2022-06-01 2
419
+ 4 2022-07-01 3
420
+ 5 2022-08-01 3
421
+ 6 2022-09-01 3
422
+ 7 2022-10-01 4
423
+ """
424
+ def formatter(column, _timezone):
425
+ column = ott.value2str(column)
426
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
427
+ return f'QUARTER({column},{_timezone})'
428
+
429
+ return _DtAccessor.Formatter(
430
+ op_params=[self._base_column, timezone],
431
+ dtype=int,
432
+ formatter=formatter,
433
+ )
434
+
435
+ @docstring(parameters=[_timezone_doc], add_self=True)
436
+ def year(self, timezone=None):
437
+ """
438
+ Return the year.
439
+
440
+ Examples
441
+ --------
442
+ >>> data = otp.Ticks(X=[otp.dt(2020 + i, 3, 1) for i in range(3, 11)])
443
+ >>> data['YEAR'] = data['X'].dt.year()
444
+ >>> otp.run(data)[['X', 'YEAR']]
445
+ X YEAR
446
+ 0 2023-03-01 2023
447
+ 1 2024-03-01 2024
448
+ 2 2025-03-01 2025
449
+ 3 2026-03-01 2026
450
+ 4 2027-03-01 2027
451
+ 5 2028-03-01 2028
452
+ 6 2029-03-01 2029
453
+ 7 2030-03-01 2030
454
+ """
455
+ def formatter(column, _timezone):
456
+ column = ott.value2str(column)
457
+ _timezone, _ = self._preprocess_tz_and_format(_timezone, '')
458
+ return f'YEAR({column},{_timezone})'
459
+
460
+ return _DtAccessor.Formatter(
461
+ op_params=[self._base_column, timezone],
462
+ dtype=int,
463
+ formatter=formatter,
464
+ )
465
+
466
+ @docstring(parameters=[_timezone_doc], add_self=True)
467
+ def date_trunc(self,
468
+ date_part: Literal['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second',
469
+ 'millisecond', 'nanosecond'],
470
+ timezone=None):
471
+ """
472
+ Truncates to the specified precision.
473
+
474
+ Parameters
475
+ ----------
476
+ date_part: str | Operation | Column
477
+ Precision to truncate datetime to. Possible values are 'year', 'quarter', 'month', 'week', 'day', 'hour',
478
+ 'minute', 'second', 'millisecond' and 'nanosecond'.
479
+ Notice that beginning of week is considered to be Sunday.
480
+
481
+ Examples
482
+ --------
483
+ >>> data = otp.Ticks(X=[otp.dt(2020, 11, 11, 5, 4, 13, 101737, 879)] * 7,
484
+ ... DATE_PART=['year', 'day', 'hour', 'minute', 'second', 'millisecond', 'nanosecond'])
485
+ >>> data['TRUNCATED_X'] = data['X'].dt.date_trunc(data['DATE_PART'])
486
+ >>> otp.run(data)[['X', 'TRUNCATED_X', 'DATE_PART']]
487
+ X TRUNCATED_X DATE_PART
488
+ 0 2020-11-11 05:04:13.101737879 2020-01-01 00:00:00.000000000 year
489
+ 1 2020-11-11 05:04:13.101737879 2020-11-11 00:00:00.000000000 day
490
+ 2 2020-11-11 05:04:13.101737879 2020-11-11 05:00:00.000000000 hour
491
+ 3 2020-11-11 05:04:13.101737879 2020-11-11 05:04:00.000000000 minute
492
+ 4 2020-11-11 05:04:13.101737879 2020-11-11 05:04:13.000000000 second
493
+ 5 2020-11-11 05:04:13.101737879 2020-11-11 05:04:13.101000000 millisecond
494
+ 6 2020-11-11 05:04:13.101737879 2020-11-11 05:04:13.101737879 nanosecond
495
+ """
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
+ )
507
+
508
+ @docstring(parameters=[_timezone_doc], add_self=True)
509
+ def week(self, timezone=None):
510
+ """
511
+ Returns the week.
512
+
513
+ Examples
514
+ --------
515
+ >>> data = otp.Ticks(X=[otp.dt(2020, i, 1) for i in range(3, 11)])
516
+ >>> data['WEEK'] = data['X'].dt.week()
517
+ >>> otp.run(data)[['X', 'WEEK']]
518
+ X WEEK
519
+ 0 2020-03-01 10
520
+ 1 2020-04-01 14
521
+ 2 2020-05-01 18
522
+ 3 2020-06-01 23
523
+ 4 2020-07-01 27
524
+ 5 2020-08-01 31
525
+ 6 2020-09-01 36
526
+ 7 2020-10-01 40
527
+ """
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
+ )