Skip to content

Commit

Permalink
FIX: InstrumentMap support for mixed stypes
Browse files Browse the repository at this point in the history
  • Loading branch information
nmacholl committed Jan 9, 2024
1 parent e1615df commit ebbedfa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions databento/common/symbology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion tests/test_common_symbology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -224,6 +232,7 @@ def test_instrument_map_insert_metadata(
]

metadata = create_metadata(
stype_in=stype_in,
mappings=mappings,
)

Expand Down

0 comments on commit ebbedfa

Please sign in to comment.