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