Skip to content

Commit 7215e0e

Browse files
committed
MOD: Upgrade databento-dbn to v0.18.0
1 parent d133ae5 commit 7215e0e

File tree

8 files changed

+80
-24
lines changed

8 files changed

+80
-24
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
## 0.35.0 - TBD
44

5+
#### Enhancements
6+
- Upgraded `databento-dbn` to 0.18.0
7+
58
#### Breaking changes
6-
- Rename `use_snapshot` parameter in `Live.subscribe` function to `snapshot`
9+
- Renamed `CbboMsg` to `CBBOMsg`.
10+
- Renamed `use_snapshot` parameter in `Live.subscribe` function to `snapshot`
11+
- All Python exceptions raised by `databento-dbn` have been changed to use the `DBNError` type
712

813
## 0.34.1 - 2024-05-21
914

@@ -14,7 +19,7 @@
1419

1520
#### Enhancements
1621
- Added `pip-system-certs` dependency for Windows platforms to prevent a connection issue in `requests` when behind a proxy
17-
- Iteration of the `Live` client will now automatically call `Live.stop` when the iterator is destroyed, such as when a for loop is escaped with an exception or `break` statement.
22+
- Iteration of the `Live` client will now automatically call `Live.stop` when the iterator is destroyed, such as when a for loop is escaped with an exception or `break` statement
1823

1924
#### Bug fixes
2025
- Fixed an issue where `batch.download` and `batch.download_async` would fail if requested files already existed in the output directory

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.17.1"
35+
- databento-dbn = "0.18.0"
3636
- numpy= ">=1.23.5"
3737
- pandas = ">=1.5.3"
3838
- pip-system-certs = ">=4.0" (Windows only)

databento/common/constants.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Final
44

55
import numpy as np
6-
from databento_dbn import CbboMsg
6+
from databento_dbn import CBBOMsg
77
from databento_dbn import ImbalanceMsg
88
from databento_dbn import InstrumentDefMsg
99
from databento_dbn import InstrumentDefMsgV1
@@ -41,10 +41,10 @@
4141
Schema.STATISTICS: StatMsg,
4242
Schema.TBBO: MBP1Msg,
4343
Schema.TRADES: TradeMsg,
44-
Schema.CBBO: CbboMsg,
45-
Schema.CBBO_1S: CbboMsg,
46-
Schema.CBBO_1M: CbboMsg,
47-
Schema.TCBBO: CbboMsg,
44+
Schema.CBBO: CBBOMsg,
45+
Schema.CBBO_1S: CBBOMsg,
46+
Schema.CBBO_1M: CBBOMsg,
47+
Schema.TCBBO: CBBOMsg,
4848
Schema.BBO_1S: MBP1Msg,
4949
Schema.BBO_1M: MBP1Msg,
5050
}

databento/common/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
DBNRecord = Union[
12-
databento_dbn.CbboMsg,
12+
databento_dbn.CBBOMsg,
1313
databento_dbn.MBOMsg,
1414
databento_dbn.MBP1Msg,
1515
databento_dbn.MBP10Msg,

databento/common/validation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from urllib.parse import urlsplit
99
from urllib.parse import urlunsplit
1010

11+
from databento_dbn import DBNError
12+
1113

1214
E = TypeVar("E", bound=Enum)
1315

@@ -109,7 +111,7 @@ def validate_enum(
109111
"""
110112
try:
111113
return enum(value)
112-
except ValueError:
114+
except (ValueError, DBNError):
113115
if hasattr(enum, "variants"):
114116
valid = list(map(str, enum.variants())) # type: ignore [attr-defined]
115117
else:

databento/live/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def _process_gateway(self, data: bytes) -> None:
360360
try:
361361
self._gateway_decoder.write(data)
362362
controls = self._gateway_decoder.decode()
363-
except ValueError:
363+
except Exception:
364364
logger.exception("error decoding control message")
365365
self.transport.close()
366366
raise

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.17.1"
35+
databento-dbn = "0.18.0"
3636
numpy = [
3737
{version = ">=1.23.5", python = "<3.12"},
3838
{version = "^1.26.0", python = "^3.12"}

tests/test_common_enums.py

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from enum import Enum
88
from enum import Flag
99
from itertools import combinations
10+
from typing import Final
1011

1112
import pytest
1213
from databento.common.enums import Delivery
@@ -20,31 +21,35 @@
2021
from databento.common.enums import SymbologyResolution
2122
from databento.common.publishers import Dataset
2223
from databento_dbn import Compression
24+
from databento_dbn import DBNError
2325
from databento_dbn import Encoding
2426
from databento_dbn import Schema
2527
from databento_dbn import SType
2628

2729

28-
DATABENTO_ENUMS = (
29-
Compression,
30+
NATIVE_ENUMS: Final = (
3031
Dataset,
31-
Encoding,
3232
FeedMode,
3333
HistoricalGateway,
3434
Packaging,
3535
Delivery,
3636
RecordFlags,
3737
RollRule,
38-
Schema,
3938
SplitDuration,
40-
SType,
4139
SymbologyResolution,
4240
)
4341

42+
DBN_ENUMS: Final = (
43+
Compression,
44+
Encoding,
45+
Schema,
46+
SType,
47+
)
48+
4449

4550
@pytest.mark.parametrize(
4651
"enum_type",
47-
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, int)),
52+
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, int)),
4853
)
4954
def test_int_enum_string_coercion(enum_type: type[Enum]) -> None:
5055
"""
@@ -62,7 +67,7 @@ def test_int_enum_string_coercion(enum_type: type[Enum]) -> None:
6267

6368
@pytest.mark.parametrize(
6469
"enum_type",
65-
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, str)),
70+
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, str)),
6671
)
6772
def test_str_enum_case_coercion(enum_type: type[Enum]) -> None:
6873
"""
@@ -81,7 +86,7 @@ def test_str_enum_case_coercion(enum_type: type[Enum]) -> None:
8186

8287
@pytest.mark.parametrize(
8388
"enum_type",
84-
DATABENTO_ENUMS,
89+
NATIVE_ENUMS,
8590
)
8691
def test_enum_name_coercion(enum_type: type[Enum]) -> None:
8792
"""
@@ -109,7 +114,34 @@ def test_enum_name_coercion(enum_type: type[Enum]) -> None:
109114

110115
@pytest.mark.parametrize(
111116
"enum_type",
112-
(pytest.param(enum) for enum in DATABENTO_ENUMS),
117+
DBN_ENUMS,
118+
)
119+
def test_dbn_enum_name_coercion(enum_type: type[Enum]) -> None:
120+
"""
121+
Test that DBN enums can be coerced from the member names.
122+
123+
This includes case and dash conversion to underscores.
124+
125+
"""
126+
# Arrange, Act
127+
if enum_type in (Compression, Encoding, Schema, SType):
128+
enum_it = iter(enum_type.variants()) # type: ignore [attr-defined]
129+
else:
130+
enum_it = iter(enum_type)
131+
132+
# Assert
133+
for enum in enum_it:
134+
assert enum == enum_type(enum.name)
135+
assert enum == enum_type(enum.name.replace("_", "-"))
136+
assert enum == enum_type(enum.name.lower())
137+
assert enum == enum_type(enum.name.upper())
138+
with pytest.raises(DBNError):
139+
enum_type("bar") # sanity
140+
141+
142+
@pytest.mark.parametrize(
143+
"enum_type",
144+
(pytest.param(enum) for enum in NATIVE_ENUMS),
113145
)
114146
def test_enum_none_not_coercible(enum_type: type[Enum]) -> None:
115147
"""
@@ -129,7 +161,24 @@ def test_enum_none_not_coercible(enum_type: type[Enum]) -> None:
129161

130162
@pytest.mark.parametrize(
131163
"enum_type",
132-
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, int)),
164+
(pytest.param(enum) for enum in DBN_ENUMS),
165+
)
166+
def test_dbn_enum_none_not_coercible(enum_type: type[Enum]) -> None:
167+
"""
168+
Test that None type is not coercible and raises a TypeError.
169+
"""
170+
# Arrange, Act
171+
if enum_type == Compression:
172+
enum_type(None)
173+
else:
174+
# Assert
175+
with pytest.raises(DBNError):
176+
enum_type(None)
177+
178+
179+
@pytest.mark.parametrize(
180+
"enum_type",
181+
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, int)),
133182
)
134183
def test_int_enum_stringy_mixin(enum_type: type[Enum]) -> None:
135184
"""
@@ -149,7 +198,7 @@ def test_int_enum_stringy_mixin(enum_type: type[Enum]) -> None:
149198

150199
@pytest.mark.parametrize(
151200
"enum_type",
152-
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, str)),
201+
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, str)),
153202
)
154203
def test_str_enum_stringy_mixin(enum_type: type[Enum]) -> None:
155204
"""
@@ -169,7 +218,7 @@ def test_str_enum_stringy_mixin(enum_type: type[Enum]) -> None:
169218

170219
@pytest.mark.parametrize(
171220
"enum_type",
172-
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, Flag)),
221+
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, Flag)),
173222
)
174223
def test_int_flags_stringy_mixin(enum_type: type[Flag]) -> None:
175224
"""

0 commit comments

Comments
 (0)