Skip to content

Commit ebbedfa

Browse files
committed
FIX: InstrumentMap support for mixed stypes
1 parent e1615df commit ebbedfa

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Fixed an issue where sending lots of subscriptions could cause a `BufferError`
1111
- Fixed an issue where `Historical.batch.download` was slow
1212
- Fixed an issue where `Historical.timeseries.get_range` was slow
13+
- Fixed an issue where reading a DBN file with non-empty metadata symbol mappings and mixed `SType` would cause an error when mapping symbols (credit: Jakob Lövhall)
1314

1415
## 0.24.1 - 2023-12-15
1516

databento/common/symbology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ def insert_metadata(self, metadata: Metadata) -> None:
242242
# Nothing to do
243243
return
244244

245-
stype_in = SType(metadata.stype_in)
246-
stype_out = SType(metadata.stype_out)
245+
stype_in = SType(metadata.stype_in) if metadata.stype_in is not None else None
246+
stype_out = SType(metadata.stype_out) if metadata.stype_out is not None else None
247247

248248
for symbol_in, entries in metadata.mappings.items():
249249
for entry in entries:

tests/test_common_symbology.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def create_metadata(
166166
dataset: str = "UNIT.TEST",
167167
start: int = UNDEF_TIMESTAMP,
168168
end: int = UNDEF_TIMESTAMP,
169-
stype_in: SType = SType.RAW_SYMBOL,
169+
stype_in: SType | None = SType.RAW_SYMBOL,
170170
stype_out: SType = SType.INSTRUMENT_ID,
171171
schema: Schema = Schema.TRADES,
172172
limit: int | None = None,
@@ -198,10 +198,18 @@ def test_instrument_map(
198198
assert instrument_map._data == {}
199199

200200

201+
@pytest.mark.parametrize(
202+
"stype_in",
203+
[
204+
SType.RAW_SYMBOL,
205+
None,
206+
],
207+
)
201208
def test_instrument_map_insert_metadata(
202209
instrument_map: InstrumentMap,
203210
start_date: pd.Timestamp,
204211
end_date: pd.Timestamp,
212+
stype_in: SType | None,
205213
) -> None:
206214
"""
207215
Test the insertion of DBN Metadata.
@@ -224,6 +232,7 @@ def test_instrument_map_insert_metadata(
224232
]
225233

226234
metadata = create_metadata(
235+
stype_in=stype_in,
227236
mappings=mappings,
228237
)
229238

0 commit comments

Comments
 (0)