Skip to content

Commit 7cef828

Browse files
committed
FIX: Invalid symbol mappings from tz offset
1 parent 2e8ce08 commit 7cef828

File tree

3 files changed

+79
-95
lines changed

3 files changed

+79
-95
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
## 0.30.0 - TBD
44

55
#### Enhancements
6-
- Changed how `SymbolMappingMsg` objects are ingested by `InstrumentMap` to single source the timestamp parsing from the `dbn` package.
6+
- Changed how `SymbolMappingMsg` objects are ingested by `InstrumentMap` to single source the timestamp parsing from the `databento-dbn` package
7+
8+
#### Bug fixes
9+
- Fixed an issue where setting a timezone in `DBNStore.to_df` could cause invalid symbol mappings
710

811
#### Breaking changes
9-
- Changed `Live.add_stream` to use the exclusive write mode when handling file paths so existing files won't be overwritten.
12+
- Changed `Live.add_stream` to use the exclusive write mode when handling file paths so existing files won't be overwritten
1013

1114
## 0.29.0 - 2024-02-13
1215

databento/common/dbnstore.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,16 +1378,19 @@ def __next__(self) -> pd.DataFrame:
13781378

13791379
self._format_hidden_fields(df)
13801380

1381-
self._format_px(df, self._price_type)
1382-
13831381
if self._pretty_ts:
13841382
self._format_pretty_ts(df)
13851383

1386-
self._format_set_index(df)
1387-
13881384
if self._map_symbols:
13891385
self._format_map_symbols(df)
13901386

1387+
if self._pretty_ts:
1388+
self._format_timezone(df)
1389+
1390+
self._format_px(df, self._price_type)
1391+
1392+
self._format_set_index(df)
1393+
13911394
return df
13921395

13931396
def _format_definition_fields(self, df: pd.DataFrame) -> None:
@@ -1402,13 +1405,20 @@ def _format_hidden_fields(self, df: pd.DataFrame) -> None:
14021405
df[column] = df[column].str.decode("utf-8")
14031406

14041407
def _format_map_symbols(self, df: pd.DataFrame) -> None:
1405-
df_index = df.index if self._pretty_ts else pd.to_datetime(df.index, utc=True)
1408+
# the first ordered field will be ts_recv or ts_event when appropriate
1409+
ts_name = self._struct_type._ordered_fields[0]
1410+
1411+
df_index = df[ts_name] if self._pretty_ts else pd.to_datetime(df[ts_name], utc=True)
14061412
dates = [ts.date() for ts in df_index]
14071413
df["symbol"] = [
14081414
self._instrument_map.resolve(inst, dates[i])
14091415
for i, inst in enumerate(df["instrument_id"])
14101416
]
14111417

1418+
def _format_timezone(self, df: pd.DataFrame) -> None:
1419+
for field in self._struct_type._timestamp_fields:
1420+
df[field] = df[field].dt.tz_convert(self._tz)
1421+
14121422
def _format_px(
14131423
self,
14141424
df: pd.DataFrame,
@@ -1429,8 +1439,9 @@ def _format_px(
14291439

14301440
def _format_pretty_ts(self, df: pd.DataFrame) -> None:
14311441
for field in self._struct_type._timestamp_fields:
1432-
df[field] = pd.to_datetime(df[field], utc=True, errors="coerce").dt.tz_convert(self._tz)
1442+
df[field] = pd.to_datetime(df[field], utc=True, errors="coerce")
14331443

14341444
def _format_set_index(self, df: pd.DataFrame) -> None:
1445+
# the first ordered field will be ts_recv or ts_event when appropriate
14351446
index_column = self._struct_type._ordered_fields[0]
14361447
df.set_index(index_column, inplace=True)

0 commit comments

Comments
 (0)