onetick-py 1.162.2__py3-none-any.whl → 1.164.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.
- locator_parser/actions.py +10 -14
- locator_parser/common.py +13 -10
- locator_parser/io.py +6 -4
- locator_parser/locator.py +1 -1
- onetick/doc_utilities/ot_doctest.py +1 -1
- onetick/doc_utilities/snippets.py +1 -2
- onetick/lib/instance.py +7 -4
- onetick/py/__init__.py +5 -9
- onetick/py/_version.py +1 -1
- onetick/py/aggregations/_base.py +7 -4
- onetick/py/aggregations/_docs.py +22 -7
- onetick/py/aggregations/other.py +1 -1
- onetick/py/cache.py +1 -0
- onetick/py/callback/callback.py +1 -0
- onetick/py/core/_internal/_proxy_node.py +1 -1
- onetick/py/core/_internal/_state_objects.py +2 -2
- onetick/py/core/_source/source_methods/aggregations.py +8 -9
- onetick/py/core/_source/source_methods/applyers.py +2 -2
- onetick/py/core/_source/source_methods/debugs.py +16 -14
- onetick/py/core/_source/source_methods/drops.py +1 -1
- onetick/py/core/_source/source_methods/fields.py +5 -5
- onetick/py/core/_source/source_methods/filters.py +4 -3
- onetick/py/core/_source/source_methods/joins.py +6 -6
- onetick/py/core/_source/source_methods/misc.py +84 -0
- onetick/py/core/_source/source_methods/renames.py +3 -3
- onetick/py/core/_source/source_methods/switches.py +3 -3
- onetick/py/core/_source/source_methods/writes.py +279 -10
- onetick/py/core/_source/tmp_otq.py +1 -1
- onetick/py/core/column_operations/_methods/_internal.py +1 -1
- onetick/py/core/column_operations/_methods/methods.py +8 -7
- onetick/py/core/column_operations/_methods/op_types.py +1 -0
- onetick/py/core/column_operations/accessors/dt_accessor.py +4 -0
- onetick/py/core/column_operations/base.py +5 -5
- onetick/py/core/cut_builder.py +1 -0
- onetick/py/core/eval_query.py +1 -0
- onetick/py/core/lambda_object.py +2 -3
- onetick/py/core/per_tick_script.py +6 -5
- onetick/py/core/query_inspector.py +6 -7
- onetick/py/core/source.py +11 -8
- onetick/py/db/_inspection.py +4 -8
- onetick/py/db/db.py +4 -100
- onetick/py/docs/docstring_parser.py +1 -1
- onetick/py/functions.py +48 -11
- onetick/py/license.py +2 -0
- onetick/py/math.py +2 -2
- onetick/py/otq.py +1 -2
- onetick/py/run.py +8 -7
- onetick/py/servers.py +2 -2
- onetick/py/session.py +8 -6
- onetick/py/sources/common.py +6 -4
- onetick/py/sources/data_source.py +25 -35
- onetick/py/sources/query.py +7 -7
- onetick/py/sources/symbols.py +1 -1
- onetick/py/sources/ticks.py +3 -3
- onetick/py/state.py +1 -0
- onetick/py/types.py +27 -25
- onetick/py/utils/config.py +2 -2
- onetick/py/utils/perf.py +2 -3
- onetick/py/utils/temp.py +2 -2
- {onetick_py-1.162.2.dist-info → onetick_py-1.164.0.dist-info}/METADATA +1 -1
- {onetick_py-1.162.2.dist-info → onetick_py-1.164.0.dist-info}/RECORD +65 -65
- {onetick_py-1.162.2.dist-info → onetick_py-1.164.0.dist-info}/WHEEL +0 -0
- {onetick_py-1.162.2.dist-info → onetick_py-1.164.0.dist-info}/entry_points.txt +0 -0
- {onetick_py-1.162.2.dist-info → onetick_py-1.164.0.dist-info}/licenses/LICENSE +0 -0
- {onetick_py-1.162.2.dist-info → onetick_py-1.164.0.dist-info}/top_level.txt +0 -0
onetick/py/run.py
CHANGED
|
@@ -494,7 +494,7 @@ def run(query: Union[Callable, Dict, otp.Source, otp.MultiOutputSource, # NOSON
|
|
|
494
494
|
query = otp.MultiOutputSource(query)
|
|
495
495
|
|
|
496
496
|
params_saved_to_otq = {}
|
|
497
|
-
if isinstance(query, otp.Source
|
|
497
|
+
if isinstance(query, (otp.Source, otp.MultiOutputSource)):
|
|
498
498
|
start = None if start is utils.adaptive else start
|
|
499
499
|
end = None if end is utils.adaptive else end
|
|
500
500
|
params_saved_to_otq = dict(
|
|
@@ -660,9 +660,9 @@ def _form_dict_from_list(data_list, output_structure):
|
|
|
660
660
|
d = defaultdict(list)
|
|
661
661
|
for node, df in lst:
|
|
662
662
|
d[node].append(df)
|
|
663
|
-
for node in d.
|
|
664
|
-
if len(
|
|
665
|
-
d[node] =
|
|
663
|
+
for node, node_list in d.items():
|
|
664
|
+
if len(node_list) == 1:
|
|
665
|
+
d[node] = node_list[0]
|
|
666
666
|
if len(d) == 1:
|
|
667
667
|
d = list(d.values())[0]
|
|
668
668
|
else: # converting defaultdict to regular dict
|
|
@@ -671,7 +671,7 @@ def _form_dict_from_list(data_list, output_structure):
|
|
|
671
671
|
|
|
672
672
|
def get_dataframe(data):
|
|
673
673
|
if output_structure == 'df':
|
|
674
|
-
return pd.DataFrame(
|
|
674
|
+
return pd.DataFrame(dict(data))
|
|
675
675
|
else:
|
|
676
676
|
import polars
|
|
677
677
|
if isinstance(data, polars.DataFrame):
|
|
@@ -749,7 +749,7 @@ def _process_empty_results(result, query_schema, output_structure):
|
|
|
749
749
|
(field, np.array([], dtype=otp.types.type2np(dtype)))
|
|
750
750
|
for field, dtype in {**query_schema, 'Time': otp.nsectime}.items()
|
|
751
751
|
]
|
|
752
|
-
if
|
|
752
|
+
if isinstance(result, otq.SymbolNumpyResultMap):
|
|
753
753
|
empty_data = dict(schema)
|
|
754
754
|
else:
|
|
755
755
|
empty_data = schema
|
|
@@ -758,7 +758,7 @@ def _process_empty_results(result, query_schema, output_structure):
|
|
|
758
758
|
import polars
|
|
759
759
|
empty_data = polars.DataFrame(dict(schema))
|
|
760
760
|
|
|
761
|
-
if
|
|
761
|
+
if isinstance(result, otq.SymbolNumpyResultMap):
|
|
762
762
|
for result_item in result.get_dict().values():
|
|
763
763
|
for node_name, symbol_result in result_item.items():
|
|
764
764
|
if len(symbol_result[0]) == 0:
|
|
@@ -814,6 +814,7 @@ def _get_start_end(start, end, timezone):
|
|
|
814
814
|
|
|
815
815
|
# `isinstance(obj, datetime.date)` is not correct because
|
|
816
816
|
# isinstance(<datetime.datetime object>, datetime.date) = True
|
|
817
|
+
# pylint: disable=unidiomatic-typecheck
|
|
817
818
|
if type(start) is datetime.date:
|
|
818
819
|
start = datetime.datetime(start.year, start.month, start.day)
|
|
819
820
|
if type(end) is datetime.date:
|
onetick/py/servers.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Optional, Union
|
|
1
|
+
from typing import Optional, Union
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class RemoteTS:
|
|
@@ -96,7 +96,7 @@ class RemoteTS:
|
|
|
96
96
|
return self.__str__()
|
|
97
97
|
|
|
98
98
|
def __str__(self):
|
|
99
|
-
if isinstance(self._host, FaultTolerance
|
|
99
|
+
if isinstance(self._host, (FaultTolerance, LoadBalancing)):
|
|
100
100
|
return str(self._host)
|
|
101
101
|
url = f'{self._host}:{self._port}'
|
|
102
102
|
if self._protocol:
|
onetick/py/session.py
CHANGED
|
@@ -16,7 +16,7 @@ from . import utils
|
|
|
16
16
|
from . import license as _license
|
|
17
17
|
from . import db as _db
|
|
18
18
|
from . import servers as _servers
|
|
19
|
-
from .
|
|
19
|
+
from . import configuration
|
|
20
20
|
from .db._inspection import databases as _databases
|
|
21
21
|
|
|
22
22
|
|
|
@@ -320,6 +320,7 @@ class ACL(_FileHandler):
|
|
|
320
320
|
def reload(self, db=None):
|
|
321
321
|
if self._session_ref is not None:
|
|
322
322
|
return utils.reload_config(db, config_type='ACCESS_LIST')
|
|
323
|
+
return None
|
|
323
324
|
|
|
324
325
|
def _read_dbs(self):
|
|
325
326
|
get_db = GetAll()
|
|
@@ -433,6 +434,7 @@ class Locator(_FileHandler):
|
|
|
433
434
|
def reload(self, db_=None):
|
|
434
435
|
if self._session_ref is not None:
|
|
435
436
|
return utils.reload_config(db_, config_type='LOCATOR')
|
|
437
|
+
return None
|
|
436
438
|
|
|
437
439
|
def _apply_actions(self, actions, print_writer=False):
|
|
438
440
|
writer = PrintWriter() if print_writer else FileWriter(self.path)
|
|
@@ -1300,11 +1302,11 @@ class TestSession(Session):
|
|
|
1300
1302
|
``DEMO_L1`` is the database defined in the default locator generated by onetick.py
|
|
1301
1303
|
and it is also a name of the database commonly used in the OneTick ecosystem, academy courses, etc.
|
|
1302
1304
|
"""
|
|
1303
|
-
config['tz'] = 'EST5EDT'
|
|
1304
|
-
config['default_db'] = 'DEMO_L1'
|
|
1305
|
-
config['default_symbol'] = 'AAPL'
|
|
1306
|
-
config['default_start_time'] = datetime(2003, 12, 1, 0, 0, 0)
|
|
1307
|
-
config['default_end_time'] = datetime(2003, 12, 4, 0, 0, 0)
|
|
1305
|
+
configuration.config['tz'] = 'EST5EDT'
|
|
1306
|
+
configuration.config['default_db'] = 'DEMO_L1'
|
|
1307
|
+
configuration.config['default_symbol'] = 'AAPL'
|
|
1308
|
+
configuration.config['default_start_time'] = datetime(2003, 12, 1, 0, 0, 0)
|
|
1309
|
+
configuration.config['default_end_time'] = datetime(2003, 12, 4, 0, 0, 0)
|
|
1308
1310
|
super().__init__(*args, **kwargs)
|
|
1309
1311
|
|
|
1310
1312
|
|
onetick/py/sources/common.py
CHANGED
|
@@ -17,25 +17,27 @@ AdaptiveDBType = Union[str, OnetickParameter, _SymbolParamColumn, Type[utils.ada
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def get_start_end_by_date(date):
|
|
20
|
-
if isinstance(date, ott.datetime
|
|
20
|
+
if isinstance(date, (ott.datetime, ott.date)):
|
|
21
21
|
start = date.start
|
|
22
22
|
end = date.end
|
|
23
|
-
|
|
23
|
+
elif isinstance(date, (dt.datetime, dt.date)):
|
|
24
24
|
start = dt.datetime(date.year, date.month, date.day)
|
|
25
25
|
end = start + dt.timedelta(days=1, milliseconds=-1)
|
|
26
|
+
else:
|
|
27
|
+
raise ValueError(f"Unsupported value of parameter 'date': {type(date)}")
|
|
26
28
|
return start, end
|
|
27
29
|
|
|
28
30
|
|
|
29
31
|
def convert_tick_type_to_str(
|
|
30
32
|
tick_type: Optional[AdaptiveTickType],
|
|
31
33
|
db: Optional[AdaptiveDBType] = None,
|
|
32
|
-
):
|
|
34
|
+
) -> Optional[str]:
|
|
33
35
|
if not isinstance(db, list) and not isinstance(db, (OnetickParameter, _SymbolParamColumn)):
|
|
34
36
|
if tick_type is utils.adaptive:
|
|
35
37
|
tick_type = 'ANY'
|
|
36
38
|
|
|
37
39
|
if isinstance(tick_type, type) or tick_type is None:
|
|
38
|
-
return
|
|
40
|
+
return None
|
|
39
41
|
|
|
40
42
|
if db is utils.adaptive_to_default or db is utils.adaptive:
|
|
41
43
|
# if default database is not set, tick type will be set without it
|
|
@@ -329,8 +329,7 @@ class DataSource(Source):
|
|
|
329
329
|
start = None # means that use the last date with data
|
|
330
330
|
|
|
331
331
|
if isinstance(db, list):
|
|
332
|
-
|
|
333
|
-
across different tick types and dbs '''
|
|
332
|
+
# This case of a merge, since we need to get combined schema across different tick types and dbs
|
|
334
333
|
for t_db in db:
|
|
335
334
|
if t_db.startswith('expr('):
|
|
336
335
|
continue
|
|
@@ -358,8 +357,8 @@ class DataSource(Source):
|
|
|
358
357
|
schema.update(db_schema)
|
|
359
358
|
|
|
360
359
|
if db is None or isinstance(db, _SymbolParamColumn):
|
|
361
|
-
|
|
362
|
-
Set to empty to indicate that in this case we expect the manually set schema.
|
|
360
|
+
# In this case we can't get schema, because db is calculated dynamically.
|
|
361
|
+
# Set to empty to indicate that in this case we expect the manually set schema.
|
|
363
362
|
schema = {}
|
|
364
363
|
return schema
|
|
365
364
|
|
|
@@ -430,22 +429,20 @@ class DataSource(Source):
|
|
|
430
429
|
|
|
431
430
|
def __prepare_db_tick_type(self, db, tick_type, start, end):
|
|
432
431
|
if isinstance(db, list):
|
|
433
|
-
|
|
434
|
-
the `db` var as a list of databases with tick types and the
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
the tick type from the `tick_type`.
|
|
448
|
-
'''
|
|
432
|
+
# If everything is correct then this branch should leave
|
|
433
|
+
# the `db` var as a list of databases with tick types and the `tick_type` var is None.
|
|
434
|
+
# Valid cases:
|
|
435
|
+
# - Fully defined case. The `db` parameter has a list of databases where
|
|
436
|
+
# every database has a tick type, when the `tick_type`
|
|
437
|
+
# parameter has default value or None (for backward compatibility)
|
|
438
|
+
# - Partially defined case. The `db` parameter has a list of databases but
|
|
439
|
+
# not every database has a tick type, and meantime the `tick_type`
|
|
440
|
+
# is passed to not None value. In that case databases without tick type
|
|
441
|
+
# are exetended with a tick type from the `tick_type` parameter
|
|
442
|
+
# - No defined case. The `db` parameter has a list of databases and
|
|
443
|
+
# every database there has no tick type, and the `tick_type` is
|
|
444
|
+
# set to not None value. In that case every database is extended with
|
|
445
|
+
# the tick type from the `tick_type`.
|
|
449
446
|
|
|
450
447
|
def db_converter(_db):
|
|
451
448
|
if isinstance(_db, DB):
|
|
@@ -483,8 +480,8 @@ class DataSource(Source):
|
|
|
483
480
|
db = db.name # ... and we go to the next branch
|
|
484
481
|
|
|
485
482
|
if isinstance(db, str):
|
|
486
|
-
|
|
487
|
-
concatenated with the `tick_type`.
|
|
483
|
+
# The resulting `db` var contains a list with string value, that has the `db`
|
|
484
|
+
# concatenated with the `tick_type`.
|
|
488
485
|
if '::' in db:
|
|
489
486
|
if tick_type is utils.adaptive or tick_type is None:
|
|
490
487
|
tick_type = db.split(':')[-1]
|
|
@@ -549,9 +546,8 @@ class DataSource(Source):
|
|
|
549
546
|
tick_type = None
|
|
550
547
|
|
|
551
548
|
if isinstance(db, _SymbolParamColumn):
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
can not be utils.adpative '''
|
|
549
|
+
# Do nothing, because we don't know whether db will come with the tick type or not.
|
|
550
|
+
# The only one thing that definetely we know that tick_type can not be utils.adaptive
|
|
555
551
|
if tick_type is utils.adaptive:
|
|
556
552
|
# TODO: need to test this case
|
|
557
553
|
raise ValueError('The `db` is set to the symbol param, in that case '
|
|
@@ -559,8 +555,7 @@ class DataSource(Source):
|
|
|
559
555
|
'or to None')
|
|
560
556
|
|
|
561
557
|
if db is None:
|
|
562
|
-
|
|
563
|
-
should be defined '''
|
|
558
|
+
# This case means that database comes with the symbol name, then tick type should be defined
|
|
564
559
|
if tick_type is utils.adaptive or tick_type is None:
|
|
565
560
|
raise ValueError('The `db` is not specified that means database is '
|
|
566
561
|
'expected to be defined with the symbol name. '
|
|
@@ -889,14 +884,9 @@ class DataSource(Source):
|
|
|
889
884
|
)
|
|
890
885
|
|
|
891
886
|
if (
|
|
892
|
-
isinstance(symbol, Source)
|
|
887
|
+
isinstance(symbol, (Source, query, _QueryEvalWrapper, otq.GraphQuery))
|
|
893
888
|
or hasattr(symbol, "__iter__")
|
|
894
|
-
and not isinstance(symbol, dict)
|
|
895
|
-
and not isinstance(symbol, str)
|
|
896
|
-
and not isinstance(symbol, (OnetickParameter, _SymbolParamColumn))
|
|
897
|
-
or isinstance(symbol, query)
|
|
898
|
-
or isinstance(symbol, _QueryEvalWrapper)
|
|
899
|
-
or isinstance(symbol, otq.GraphQuery)
|
|
889
|
+
and not isinstance(symbol, (dict, str, OnetickParameter, _SymbolParamColumn))
|
|
900
890
|
):
|
|
901
891
|
super().__init__(
|
|
902
892
|
_start=start,
|
|
@@ -965,7 +955,7 @@ class DataSource(Source):
|
|
|
965
955
|
if where_clause_for_back_ticks is not None:
|
|
966
956
|
params['where_clause_for_back_ticks'] = where_clause_for_back_ticks
|
|
967
957
|
|
|
968
|
-
if isinstance(db, list
|
|
958
|
+
if isinstance(db, (list, _SymbolParamColumn)):
|
|
969
959
|
src = self._create_source(otq.Passthrough(**params),
|
|
970
960
|
back_to_first_tick=back_to_first_tick,
|
|
971
961
|
keep_first_tick_timestamp=keep_first_tick_timestamp)
|
onetick/py/sources/query.py
CHANGED
|
@@ -70,9 +70,9 @@ class Query(Source):
|
|
|
70
70
|
schema=schema, **kwargs,
|
|
71
71
|
)
|
|
72
72
|
|
|
73
|
-
def base_ep(self,
|
|
74
|
-
nested = otq.NestedOtq(
|
|
75
|
-
graph =
|
|
73
|
+
def base_ep(self, query_object, out_pin):
|
|
74
|
+
nested = otq.NestedOtq(query_object.path, query_object.str_params)
|
|
75
|
+
graph = query_object.graph_info
|
|
76
76
|
|
|
77
77
|
if out_pin is utils.adaptive:
|
|
78
78
|
if graph is not None:
|
|
@@ -80,7 +80,7 @@ class Query(Source):
|
|
|
80
80
|
return Source(nested[graph.nested_outputs[0].NESTED_OUTPUT])
|
|
81
81
|
if len(graph.nested_outputs) > 1:
|
|
82
82
|
raise ValueError(
|
|
83
|
-
f'Query "{
|
|
83
|
+
f'Query "{query_object.query_name}" has multiple outputs, but you have not '
|
|
84
84
|
"specified which one should be used. You could specify it"
|
|
85
85
|
' using "out_pin" parameter of the Query constructor.'
|
|
86
86
|
)
|
|
@@ -91,7 +91,7 @@ class Query(Source):
|
|
|
91
91
|
existed_out_pins = set(map(operator.attrgetter("NESTED_OUTPUT"), graph.nested_outputs))
|
|
92
92
|
if out_pin not in existed_out_pins:
|
|
93
93
|
raise ValueError(
|
|
94
|
-
f'Query "{
|
|
94
|
+
f'Query "{query_object.query_name}" does not have the "{out_pin}" output, there are only following '
|
|
95
95
|
f"output pins exist: {','.join(existed_out_pins)}"
|
|
96
96
|
)
|
|
97
97
|
return Source(nested[out_pin])
|
|
@@ -369,7 +369,7 @@ class query:
|
|
|
369
369
|
def __getitem__(self, key):
|
|
370
370
|
output_pins = []
|
|
371
371
|
|
|
372
|
-
if
|
|
372
|
+
if isinstance(key, tuple):
|
|
373
373
|
output_pins = list(key)
|
|
374
374
|
elif isinstance(key, str):
|
|
375
375
|
output_pins = [key]
|
|
@@ -459,7 +459,7 @@ class query:
|
|
|
459
459
|
open_char = None
|
|
460
460
|
continue
|
|
461
461
|
|
|
462
|
-
if not open_char and
|
|
462
|
+
if not open_char and c in ("'", '"'):
|
|
463
463
|
open_char = c
|
|
464
464
|
last_inx = inx + 1
|
|
465
465
|
continue
|
onetick/py/sources/symbols.py
CHANGED
|
@@ -271,7 +271,7 @@ class Symbols(Source):
|
|
|
271
271
|
" and use parameter '_tick_type' if you want set a tick type for a node in OneTick graph.",
|
|
272
272
|
FutureWarning, stacklevel=2)
|
|
273
273
|
|
|
274
|
-
if date and
|
|
274
|
+
if date and isinstance(date, (ott.datetime, ott.date)):
|
|
275
275
|
start = date.start
|
|
276
276
|
end = date.end
|
|
277
277
|
|
onetick/py/sources/ticks.py
CHANGED
|
@@ -817,9 +817,9 @@ def TTicks(data): # NOSONAR
|
|
|
817
817
|
"You could use the `Ticks` to pass data in the same format there",
|
|
818
818
|
FutureWarning)
|
|
819
819
|
|
|
820
|
-
|
|
820
|
+
data_dict = {}
|
|
821
821
|
|
|
822
822
|
for inx, key in enumerate(data[0]):
|
|
823
|
-
|
|
823
|
+
data_dict[key] = [sub_list[inx] for sub_list in data[1:]]
|
|
824
824
|
|
|
825
|
-
return Ticks(
|
|
825
|
+
return Ticks(data_dict)
|
onetick/py/state.py
CHANGED
|
@@ -59,6 +59,7 @@ def var(default_value, scope="query"):
|
|
|
59
59
|
elif ott.is_time_type(dtype):
|
|
60
60
|
dtype = ott.nsectime
|
|
61
61
|
|
|
62
|
+
# pylint: disable-next=unidiomatic-typecheck
|
|
62
63
|
if type(default_value) is str:
|
|
63
64
|
if len(default_value) > ott.string.DEFAULT_LENGTH:
|
|
64
65
|
dtype = ott.string[len(default_value)]
|
onetick/py/types.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import ctypes
|
|
2
2
|
import functools
|
|
3
3
|
import inspect
|
|
4
|
-
import os
|
|
5
4
|
import warnings
|
|
6
5
|
from typing import Optional, Type, Union
|
|
7
6
|
from packaging.version import parse as parse_version
|
|
@@ -520,7 +519,7 @@ class _inner_string(type):
|
|
|
520
519
|
@functools.lru_cache(maxsize=None) # noqa: W1518
|
|
521
520
|
def __getitem__(cls, item):
|
|
522
521
|
|
|
523
|
-
if (
|
|
522
|
+
if (not isinstance(item, int) or item < 1) and item is not Ellipsis:
|
|
524
523
|
raise TypeError("It is not allowed to have non numeric index")
|
|
525
524
|
|
|
526
525
|
class _inner_str(string): # type: ignore[misc]
|
|
@@ -847,6 +846,7 @@ def get_object_type(obj):
|
|
|
847
846
|
return dtype
|
|
848
847
|
if is_time_type(obj):
|
|
849
848
|
return nsectime
|
|
849
|
+
# pylint: disable-next=unidiomatic-typecheck
|
|
850
850
|
if type(obj) is int and obj > long.MAX:
|
|
851
851
|
# by default we use python's int (onetick's long) for numbers
|
|
852
852
|
# in case the number is too big, let's use onetick's ulong
|
|
@@ -917,6 +917,7 @@ def get_type_by_objects(objs):
|
|
|
917
917
|
dtype = nsectime
|
|
918
918
|
|
|
919
919
|
# we assume the None value has float default value, ie NaN
|
|
920
|
+
# pylint: disable-next=unidiomatic-typecheck
|
|
920
921
|
if type(None) is dtype:
|
|
921
922
|
dtype = float
|
|
922
923
|
|
|
@@ -1271,7 +1272,7 @@ class datetime(AbstractTime):
|
|
|
1271
1272
|
return result
|
|
1272
1273
|
|
|
1273
1274
|
def _error_on_int_param(self, other, op):
|
|
1274
|
-
if
|
|
1275
|
+
if isinstance(other, int):
|
|
1275
1276
|
raise TypeError(f"unsupported operand type(s) for {op}: 'otp.datetime' and 'int'")
|
|
1276
1277
|
|
|
1277
1278
|
def __str__(self):
|
|
@@ -1735,7 +1736,7 @@ def str2type(type_name: str):
|
|
|
1735
1736
|
|
|
1736
1737
|
def type2np(t):
|
|
1737
1738
|
if issubclass(t, str):
|
|
1738
|
-
if issubclass(t, otp.string) and
|
|
1739
|
+
if issubclass(t, otp.string) and isinstance(t.length, int):
|
|
1739
1740
|
return '<U' + str(t.length)
|
|
1740
1741
|
return '<U64'
|
|
1741
1742
|
elif issubclass(t, bool):
|
|
@@ -1774,27 +1775,27 @@ def type2np(t):
|
|
|
1774
1775
|
|
|
1775
1776
|
# TODO: move this union of types to some common place
|
|
1776
1777
|
def datetime2expr(
|
|
1777
|
-
|
|
1778
|
+
dt_obj: Union[_datetime, _date, pd.Timestamp, date, datetime],
|
|
1778
1779
|
timezone: Optional[str] = None,
|
|
1779
1780
|
timezone_naive: Optional[str] = None,
|
|
1780
1781
|
) -> str:
|
|
1781
1782
|
"""
|
|
1782
1783
|
Convert python datetime values to OneTick string representation.
|
|
1783
|
-
If
|
|
1784
|
-
If
|
|
1784
|
+
If ``dt_obj`` is timezone-aware then timezone will be taken from ``dt_obj`` value.
|
|
1785
|
+
If ``dt_obj`` is timezone-naive then timezone specified with otp.config['tz'] or otp.run() will be used.
|
|
1785
1786
|
|
|
1786
1787
|
Parameters
|
|
1787
1788
|
----------
|
|
1788
|
-
|
|
1789
|
+
dt_obj
|
|
1789
1790
|
date or datetime value
|
|
1790
1791
|
timezone: str or Operation
|
|
1791
1792
|
This timezone will be used unconditionally.
|
|
1792
1793
|
timezone_naive: str or Operation
|
|
1793
|
-
This timezone will be used if
|
|
1794
|
+
This timezone will be used if ``dt_obj`` is timezone-naive.
|
|
1794
1795
|
"""
|
|
1795
|
-
dt_str = _format_datetime(
|
|
1796
|
+
dt_str = _format_datetime(dt_obj, '%Y-%m-%d %H:%M:%S.%f', add_nano_suffix=True)
|
|
1796
1797
|
if timezone is None:
|
|
1797
|
-
timezone = get_timezone_from_datetime(
|
|
1798
|
+
timezone = get_timezone_from_datetime(dt_obj)
|
|
1798
1799
|
if timezone is None:
|
|
1799
1800
|
timezone = timezone_naive
|
|
1800
1801
|
if not isinstance(timezone, otp.Operation):
|
|
@@ -1802,16 +1803,16 @@ def datetime2expr(
|
|
|
1802
1803
|
return f'PARSE_NSECTIME("%Y-%m-%d %H:%M:%S.%J", "{dt_str}", {str(timezone)})'
|
|
1803
1804
|
|
|
1804
1805
|
|
|
1805
|
-
def datetime2timeval(
|
|
1806
|
+
def datetime2timeval(dt_obj: Union[_datetime, _date, pd.Timestamp, date, datetime], timezone: str = 'GMT'):
|
|
1806
1807
|
"""
|
|
1807
1808
|
Get nanosecond-precision pyomd.timeval_t
|
|
1808
1809
|
from different datetime types supported by onetick-py.
|
|
1809
1810
|
|
|
1810
|
-
If ``
|
|
1811
|
-
If ``
|
|
1811
|
+
If ``dt_obj`` is timezone-aware, then its timezone will be used.
|
|
1812
|
+
If ``dt_obj`` is timezone-naive , then it will be localized to ``timezone`` parameter (GMT by default).
|
|
1812
1813
|
"""
|
|
1813
|
-
dt_str = _format_datetime(
|
|
1814
|
-
tz_str = get_timezone_from_datetime(
|
|
1814
|
+
dt_str = _format_datetime(dt_obj, '%Y-%m-%d %H:%M:%S.%f', add_nano_suffix=True)
|
|
1815
|
+
tz_str = get_timezone_from_datetime(dt_obj)
|
|
1815
1816
|
if tz_str:
|
|
1816
1817
|
# use timezone from the object
|
|
1817
1818
|
return pyomd.TimeParser('%Y-%m-%d %H:%M:%S.%J', tz_str).parse_time(dt_str)
|
|
@@ -1820,11 +1821,11 @@ def datetime2timeval(dt: Union[_datetime, _date, pd.Timestamp, date, datetime],
|
|
|
1820
1821
|
return pyomd.TimeParser('%Y-%m-%d %H:%M:%S.%J', timezone).parse_time(dt_str)
|
|
1821
1822
|
|
|
1822
1823
|
|
|
1823
|
-
def _format_datetime(
|
|
1824
|
-
dt_str =
|
|
1824
|
+
def _format_datetime(dt_obj, fmt, add_nano_suffix=True):
|
|
1825
|
+
dt_str = dt_obj.strftime(fmt)
|
|
1825
1826
|
if add_nano_suffix:
|
|
1826
|
-
if isinstance(
|
|
1827
|
-
dt_str += f'{
|
|
1827
|
+
if isinstance(dt_obj, (pd.Timestamp, datetime)):
|
|
1828
|
+
dt_str += f'{dt_obj.nanosecond:03}'[-3:]
|
|
1828
1829
|
else:
|
|
1829
1830
|
dt_str += '000'
|
|
1830
1831
|
return dt_str
|
|
@@ -1933,15 +1934,15 @@ def is_time_type(time):
|
|
|
1933
1934
|
return issubclass(time, (_date, datetime, date))
|
|
1934
1935
|
|
|
1935
1936
|
|
|
1936
|
-
def next_day(
|
|
1937
|
+
def next_day(dt_obj: Union[_date, _datetime, date, datetime, pd.Timestamp]) -> _datetime:
|
|
1937
1938
|
"""
|
|
1938
|
-
Return next day of
|
|
1939
|
+
Return next day of ``dt_obj`` as datetime.datetime.
|
|
1939
1940
|
"""
|
|
1940
|
-
updated_dt =
|
|
1941
|
+
updated_dt = dt_obj + Day(1)
|
|
1941
1942
|
|
|
1942
1943
|
# If we switch ts on timezone transition time, ts changes its timezone offset
|
|
1943
|
-
if hasattr(
|
|
1944
|
-
dt_offset =
|
|
1944
|
+
if hasattr(dt_obj, "tzinfo") and updated_dt.tzinfo != dt_obj.tzinfo:
|
|
1945
|
+
dt_offset = dt_obj.tzinfo.utcoffset(dt_obj)
|
|
1945
1946
|
updated_dt_offset = updated_dt.tzinfo.utcoffset(updated_dt)
|
|
1946
1947
|
|
|
1947
1948
|
tz_diff = dt_offset - updated_dt_offset
|
|
@@ -2005,6 +2006,7 @@ def default_by_type(dtype):
|
|
|
2005
2006
|
return dtype('')
|
|
2006
2007
|
if issubclass(dtype, nsectime) or issubclass(dtype, msectime):
|
|
2007
2008
|
return dtype(0)
|
|
2009
|
+
raise TypeError(f"Can't get default value for type: {dtype}")
|
|
2008
2010
|
|
|
2009
2011
|
|
|
2010
2012
|
class timedelta(pd.Timedelta):
|
onetick/py/utils/config.py
CHANGED
|
@@ -8,7 +8,7 @@ from onetick.py.otq import otq
|
|
|
8
8
|
|
|
9
9
|
from .temp import TmpFile, TmpDir, ONE_TICK_TMP_DIR
|
|
10
10
|
from ..core import db_constants
|
|
11
|
-
from .
|
|
11
|
+
from . import types
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def reload_config(db=None, config_type='LOCATOR'):
|
|
@@ -113,7 +113,7 @@ def tmp_config(
|
|
|
113
113
|
acl=None,
|
|
114
114
|
otq_path=None,
|
|
115
115
|
csv_path=None,
|
|
116
|
-
clean_up=default,
|
|
116
|
+
clean_up=types.default,
|
|
117
117
|
license_path=None,
|
|
118
118
|
license_dir=None,
|
|
119
119
|
license_servers=None,
|
onetick/py/utils/perf.py
CHANGED
|
@@ -15,7 +15,7 @@ from onetick.py.core import query_inspector
|
|
|
15
15
|
from . import adaptive
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
if otp.__webapi__ or os.getenv("OTP_SKIP_OTQ_VALIDATION"
|
|
18
|
+
if otp.__webapi__ or os.getenv("OTP_SKIP_OTQ_VALIDATION"):
|
|
19
19
|
MEASURE_PERF = None
|
|
20
20
|
else:
|
|
21
21
|
# see http://solutions.pages.soltest.onetick.com/iac/onetick-server/MeasurePerf.html
|
|
@@ -294,8 +294,7 @@ class PerformanceSummary:
|
|
|
294
294
|
"""
|
|
295
295
|
Iterate over list of summary :attr:`entries`.
|
|
296
296
|
"""
|
|
297
|
-
|
|
298
|
-
yield entry
|
|
297
|
+
yield from self.entries
|
|
299
298
|
|
|
300
299
|
|
|
301
300
|
class OrdinarySummary(PerformanceSummary):
|
onetick/py/utils/temp.py
CHANGED