Skip to content

Commit 5953d18

Browse files
committed
MOD: Update definition schema struct map
1 parent fdf2d82 commit 5953d18

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

databento/common/bento.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
import numpy as np
77
import pandas as pd
88
import zstandard
9-
from databento.common.data import COLUMNS, DERIV_SCHEMAS, STRUCT_MAP
9+
from databento.common.data import (
10+
COLUMNS,
11+
DEFINITION_CHARARRAY_COLUMNS,
12+
DERIV_SCHEMAS,
13+
STRUCT_MAP,
14+
)
1015
from databento.common.enums import Compression, Encoding, Schema, SType
1116
from databento.common.logging import log_debug
1217
from databento.common.metadata import MetadataDecoder
@@ -445,13 +450,20 @@ def to_df(
445450
df["flags"] = df["flags"] & 0xFF # Apply bitmask
446451
df["side"] = df["side"].str.decode("utf-8")
447452
df["action"] = df["action"].str.decode("utf-8")
453+
elif self.schema == Schema.DEFINITION:
454+
for column in DEFINITION_CHARARRAY_COLUMNS:
455+
df[column] = df[column].str.decode("utf-8")
448456

449457
if pretty_ts:
450458
df.index = pd.to_datetime(df.index, utc=True)
451459
for column in df.columns:
452460
if column.startswith("ts_") and "delta" not in column:
453461
df[column] = pd.to_datetime(df[column], utc=True)
454462

463+
if self.schema == Schema.DEFINITION:
464+
df["expiration"] = pd.to_datetime(df["expiration"], utc=True)
465+
df["activation"] = pd.to_datetime(df["activation"], utc=True)
466+
455467
if pretty_px:
456468
for column in list(df.columns):
457469
if (

databento/common/data.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,18 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
143143
("maturity_year", np.uint16),
144144
("decay_start_date", np.uint16),
145145
("channel_id", np.uint16),
146-
("currency", "S1"), # 1 byte chararray
147-
("settl_currency", "S1"), # 1 byte chararray
148-
("secsubtype", "S1"), # 1 byte chararray
149-
("symbol", "S1"), # 1 byte chararray
150-
("group", "S1"), # 1 byte chararray
151-
("exchange", "S1"), # 1 byte chararray
152-
("asset", "S1"), # 1 byte chararray
153-
("cfi", "S1"), # 1 byte chararray
154-
("security_type", "S1"), # 1 byte chararray
155-
("unit_of_measure", "S1"), # 1 byte chararray
156-
("underlying", "S1"), # 1 byte chararray
157-
("related", "S1"), # 1 byte chararray
146+
("currency", "S4"), # 4 byte chararray
147+
("settl_currency", "S4"), # 4 byte chararray
148+
("secsubtype", "S6"), # 6 byte chararray
149+
("symbol", "S22"), # 22 byte chararray
150+
("group", "S21"), # 21 byte chararray
151+
("exchange", "S5"), # 5 byte chararray
152+
("asset", "S7"), # 7 byte chararray
153+
("cfi", "S7"), # 7 byte chararray
154+
("security_type", "S7"), # 7 byte chararray
155+
("unit_of_measure", "S31"), # 31 byte chararray
156+
("underlying", "S21"), # 21 byte chararray
157+
("related", "S21"), # 21 byte chararray
158158
("match_algorithm", "S1"), # 1 byte chararray
159159
("md_security_trading_status", np.uint8),
160160
("main_fraction", np.uint8),
@@ -170,7 +170,7 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
170170
("contract_multiplier_unit", np.int8),
171171
("flow_schedule_type", np.int8),
172172
("tick_rule", np.uint8),
173-
("dummy", "S1"), # 1 byte chararray
173+
("dummy", "S3"), # 3 byte chararray (Adjustment filler for 8-bytes alignment)
174174
],
175175
Schema.GATEWAY_ERROR: RECORD_HEADER
176176
+ [
@@ -186,6 +186,23 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
186186
],
187187
}
188188

189+
DEFINITION_CHARARRAY_COLUMNS = [
190+
"currency",
191+
"settl_currency",
192+
"secsubtype",
193+
"symbol",
194+
"group",
195+
"exchange",
196+
"asset",
197+
"cfi",
198+
"security_type",
199+
"unit_of_measure",
200+
"underlying",
201+
"related",
202+
"match_algorithm",
203+
"security_update_action",
204+
"user_defined_instrument",
205+
]
189206

190207
################################################################################
191208
# DBZ fields

0 commit comments

Comments
 (0)