diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f83c78..891ea83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fixed an issue where sending lots of subscriptions could cause a `BufferError` - Fixed an issue where `Historical.batch.download` was slow - Fixed an issue where `Historical.timeseries.get_range` was slow +- 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) ## 0.24.1 - 2023-12-15 diff --git a/databento/common/symbology.py b/databento/common/symbology.py index 0a25775..1dceffb 100644 --- a/databento/common/symbology.py +++ b/databento/common/symbology.py @@ -242,8 +242,8 @@ def insert_metadata(self, metadata: Metadata) -> None: # Nothing to do return - stype_in = SType(metadata.stype_in) - stype_out = SType(metadata.stype_out) + stype_in = SType(metadata.stype_in) if metadata.stype_in is not None else None + stype_out = SType(metadata.stype_out) if metadata.stype_out is not None else None for symbol_in, entries in metadata.mappings.items(): for entry in entries: diff --git a/tests/test_common_symbology.py b/tests/test_common_symbology.py index ca9ae25..bac23b9 100644 --- a/tests/test_common_symbology.py +++ b/tests/test_common_symbology.py @@ -166,7 +166,7 @@ def create_metadata( dataset: str = "UNIT.TEST", start: int = UNDEF_TIMESTAMP, end: int = UNDEF_TIMESTAMP, - stype_in: SType = SType.RAW_SYMBOL, + stype_in: SType | None = SType.RAW_SYMBOL, stype_out: SType = SType.INSTRUMENT_ID, schema: Schema = Schema.TRADES, limit: int | None = None, @@ -198,10 +198,18 @@ def test_instrument_map( assert instrument_map._data == {} +@pytest.mark.parametrize( + "stype_in", + [ + SType.RAW_SYMBOL, + None, + ], +) def test_instrument_map_insert_metadata( instrument_map: InstrumentMap, start_date: pd.Timestamp, end_date: pd.Timestamp, + stype_in: SType | None, ) -> None: """ Test the insertion of DBN Metadata. @@ -224,6 +232,7 @@ def test_instrument_map_insert_metadata( ] metadata = create_metadata( + stype_in=stype_in, mappings=mappings, )