Skip to content

Commit b5d0982

Browse files
committed
MOD: Upgrade to databento_dbn v0.16.0
1 parent 8bafa39 commit b5d0982

File tree

7 files changed

+42
-16
lines changed

7 files changed

+42
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#### Enhancements
66
- Added `DBNStore.insert_symbology_json` convenience method for adding symbology data from a JSON dict or file path
7+
- Upgraded `databento-dbn` to 0.16.0
78

89
## 0.30.0 - 2024-02-22
910

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The library is fully compatible with the latest distribution of Anaconda 3.8 and
3232
The minimum dependencies as found in the `pyproject.toml` are also listed below:
3333
- python = "^3.8"
3434
- aiohttp = "^3.8.3"
35-
- databento-dbn = "0.15.1"
35+
- databento-dbn = "0.16.0"
3636
- numpy= ">=1.23.5"
3737
- pandas = ">=1.5.3"
3838
- pyarrow = ">=13.0.0"

databento/common/dbnstore.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from databento.common.symbology import InstrumentMap
5050
from databento.common.types import DBNRecord
5151
from databento.common.types import Default
52+
from databento.common.types import MappingIntervalDict
5253
from databento.common.validation import validate_enum
5354
from databento.common.validation import validate_file_write_path
5455
from databento.common.validation import validate_maybe_enum
@@ -367,6 +368,7 @@ def __init__(self, data_source: DataSource) -> None:
367368
# Read metadata
368369
self._metadata: Metadata = Metadata.decode(
369370
metadata_bytes.getvalue(),
371+
upgrade_policy=VersionUpgradePolicy.AS_IS,
370372
)
371373

372374
self._instrument_map = InstrumentMap()
@@ -380,10 +382,7 @@ def __iter__(self) -> Generator[DBNRecord, None, None]:
380382
raw = reader.read(DBNStore.DBN_READ_SIZE)
381383
if raw:
382384
decoder.write(raw)
383-
try:
384-
records = decoder.decode()
385-
except ValueError:
386-
continue
385+
records = decoder.decode()
387386
for record in records:
388387
if isinstance(record, databento_dbn.Metadata):
389388
continue
@@ -471,7 +470,7 @@ def nbytes(self) -> int:
471470
return self._data_source.nbytes
472471

473472
@property
474-
def mappings(self) -> dict[str, list[dict[str, Any]]]:
473+
def mappings(self) -> dict[str, list[MappingIntervalDict]]:
475474
"""
476475
Return the symbology mappings for the data.
477476
@@ -1225,7 +1224,7 @@ def _transcode(
12251224
pretty_ts=pretty_ts,
12261225
has_metadata=True,
12271226
map_symbols=map_symbols,
1228-
symbol_interval_map=symbol_map,
1227+
symbol_interval_map=symbol_map, # type: ignore [arg-type]
12291228
schema=schema,
12301229
)
12311230

databento/common/types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import datetime as dt
12
from typing import Callable
23
from typing import Generic
4+
from typing import TypedDict
35
from typing import TypeVar
46
from typing import Union
57

@@ -19,7 +21,9 @@
1921
databento_dbn.SymbolMappingMsg,
2022
databento_dbn.SymbolMappingMsgV1,
2123
databento_dbn.SystemMsg,
24+
databento_dbn.SystemMsgV1,
2225
databento_dbn.ErrorMsg,
26+
databento_dbn.ErrorMsgV1,
2327
]
2428

2529
RecordCallback = Callable[[DBNRecord], None]
@@ -57,3 +61,23 @@ def value(self) -> _T:
5761
5862
"""
5963
return self._value
64+
65+
66+
class MappingIntervalDict(TypedDict):
67+
"""
68+
Represents a symbol mapping over a start and end date range interval.
69+
70+
Parameters
71+
----------
72+
start_date : dt.date
73+
The start of the mapping period.
74+
end_date : dt.date
75+
The end of the mapping period.
76+
symbol : str
77+
The symbol value.
78+
79+
"""
80+
81+
start_date: dt.date
82+
end_date: dt.date
83+
symbol: str

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ aiohttp = [
3232
{version = "^3.8.3", python = "<3.12"},
3333
{version = "^3.9.0", python = "^3.12"}
3434
]
35-
databento-dbn = "0.15.1"
35+
databento-dbn = "0.16.0"
3636
numpy = [
3737
{version = ">=1.23.5", python = "<3.12"},
3838
{version = "^1.26.0", python = "^3.12"}

tests/test_common_symbology.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import json
44
import pathlib
55
from collections.abc import Iterable
6+
from collections.abc import Sequence
67
from typing import Callable
78
from typing import NamedTuple
89

10+
import databento_dbn
911
import pandas as pd
1012
import pytest
1113
from databento.common.dbnstore import DBNStore
@@ -149,7 +151,7 @@ def create_symbol_mapping_message(
149151
SymbolMappingMsg
150152
151153
"""
152-
return SymbolMappingMsg(
154+
return SymbolMappingMsg( # type: ignore [call-arg]
153155
publisher_id=publisher_id,
154156
instrument_id=instrument_id,
155157
ts_event=ts_event,
@@ -163,7 +165,7 @@ def create_symbol_mapping_message(
163165

164166

165167
def create_metadata(
166-
mappings: Iterable[SymbolMapping],
168+
mappings: Sequence[databento_dbn.SymbolMapping],
167169
dataset: str = "UNIT.TEST",
168170
start: int = UNDEF_TIMESTAMP,
169171
end: int = UNDEF_TIMESTAMP,
@@ -234,7 +236,7 @@ def test_instrument_map_insert_metadata(
234236

235237
metadata = create_metadata(
236238
stype_in=stype_in,
237-
mappings=mappings,
239+
mappings=mappings, # type: ignore [arg-type]
238240
)
239241

240242
# Act
@@ -273,7 +275,7 @@ def test_instrument_map_insert_metadata_multiple_mappings(
273275
)
274276

275277
metadata = create_metadata(
276-
mappings=mappings,
278+
mappings=mappings, # type: ignore [arg-type]
277279
)
278280

279281
# Act
@@ -313,7 +315,7 @@ def test_instrument_map_insert_metadata_empty_mappings(
313315
]
314316

315317
metadata = create_metadata(
316-
mappings=mappings,
318+
mappings=mappings, # type: ignore [arg-type]
317319
)
318320

319321
# Act
@@ -360,7 +362,7 @@ def test_instrument_map_insert_symbol_mapping_message_v1(
360362
end_ts=end_date,
361363
)
362364
sym_msg_v1 = SymbolMappingMsgV1(
363-
publisher_id=sym_msg.publisher_id,
365+
publisher_id=sym_msg.publisher_id, # type: ignore [call-arg]
364366
instrument_id=sym_msg.instrument_id,
365367
ts_event=sym_msg.ts_event,
366368
stype_in_symbol=sym_msg.stype_in_symbol,

tests/test_historical_bento.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ def test_dbnstore_iterable(
788788
dbnstore = DBNStore.from_bytes(data=stub_data)
789789

790790
record_list: list[DBNRecord] = list(dbnstore)
791-
first: MBOMsg = record_list[0]
792-
second: MBOMsg = record_list[1]
791+
first: MBOMsg = record_list[0] # type: ignore [assignment]
792+
second: MBOMsg = record_list[1] # type: ignore [assignment]
793793

794794
# Assert
795795
assert first.hd.length == 14

0 commit comments

Comments
 (0)