Skip to content

Commit

Permalink
MOD: Upgrade databento-dbn to v0.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nmacholl committed May 22, 2024
1 parent d133ae5 commit 7215e0e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 24 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

## 0.35.0 - TBD

#### Enhancements
- Upgraded `databento-dbn` to 0.18.0

#### Breaking changes
- Rename `use_snapshot` parameter in `Live.subscribe` function to `snapshot`
- Renamed `CbboMsg` to `CBBOMsg`.
- Renamed `use_snapshot` parameter in `Live.subscribe` function to `snapshot`
- All Python exceptions raised by `databento-dbn` have been changed to use the `DBNError` type

## 0.34.1 - 2024-05-21

Expand All @@ -14,7 +19,7 @@

#### Enhancements
- Added `pip-system-certs` dependency for Windows platforms to prevent a connection issue in `requests` when behind a proxy
- 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.
- 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

#### Bug fixes
- Fixed an issue where `batch.download` and `batch.download_async` would fail if requested files already existed in the output directory
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The library is fully compatible with the latest distribution of Anaconda 3.8 and
The minimum dependencies as found in the `pyproject.toml` are also listed below:
- python = "^3.8"
- aiohttp = "^3.8.3"
- databento-dbn = "0.17.1"
- databento-dbn = "0.18.0"
- numpy= ">=1.23.5"
- pandas = ">=1.5.3"
- pip-system-certs = ">=4.0" (Windows only)
Expand Down
10 changes: 5 additions & 5 deletions databento/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Final

import numpy as np
from databento_dbn import CbboMsg
from databento_dbn import CBBOMsg
from databento_dbn import ImbalanceMsg
from databento_dbn import InstrumentDefMsg
from databento_dbn import InstrumentDefMsgV1
Expand Down Expand Up @@ -41,10 +41,10 @@
Schema.STATISTICS: StatMsg,
Schema.TBBO: MBP1Msg,
Schema.TRADES: TradeMsg,
Schema.CBBO: CbboMsg,
Schema.CBBO_1S: CbboMsg,
Schema.CBBO_1M: CbboMsg,
Schema.TCBBO: CbboMsg,
Schema.CBBO: CBBOMsg,
Schema.CBBO_1S: CBBOMsg,
Schema.CBBO_1M: CBBOMsg,
Schema.TCBBO: CBBOMsg,
Schema.BBO_1S: MBP1Msg,
Schema.BBO_1M: MBP1Msg,
}
Expand Down
2 changes: 1 addition & 1 deletion databento/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


DBNRecord = Union[
databento_dbn.CbboMsg,
databento_dbn.CBBOMsg,
databento_dbn.MBOMsg,
databento_dbn.MBP1Msg,
databento_dbn.MBP10Msg,
Expand Down
4 changes: 3 additions & 1 deletion databento/common/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from urllib.parse import urlsplit
from urllib.parse import urlunsplit

from databento_dbn import DBNError


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

Expand Down Expand Up @@ -109,7 +111,7 @@ def validate_enum(
"""
try:
return enum(value)
except ValueError:
except (ValueError, DBNError):
if hasattr(enum, "variants"):
valid = list(map(str, enum.variants())) # type: ignore [attr-defined]
else:
Expand Down
2 changes: 1 addition & 1 deletion databento/live/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def _process_gateway(self, data: bytes) -> None:
try:
self._gateway_decoder.write(data)
controls = self._gateway_decoder.decode()
except ValueError:
except Exception:
logger.exception("error decoding control message")
self.transport.close()
raise
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ aiohttp = [
{version = "^3.8.3", python = "<3.12"},
{version = "^3.9.0", python = "^3.12"}
]
databento-dbn = "0.17.1"
databento-dbn = "0.18.0"
numpy = [
{version = ">=1.23.5", python = "<3.12"},
{version = "^1.26.0", python = "^3.12"}
Expand Down
73 changes: 61 additions & 12 deletions tests/test_common_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from enum import Enum
from enum import Flag
from itertools import combinations
from typing import Final

import pytest
from databento.common.enums import Delivery
Expand All @@ -20,31 +21,35 @@
from databento.common.enums import SymbologyResolution
from databento.common.publishers import Dataset
from databento_dbn import Compression
from databento_dbn import DBNError
from databento_dbn import Encoding
from databento_dbn import Schema
from databento_dbn import SType


DATABENTO_ENUMS = (
Compression,
NATIVE_ENUMS: Final = (
Dataset,
Encoding,
FeedMode,
HistoricalGateway,
Packaging,
Delivery,
RecordFlags,
RollRule,
Schema,
SplitDuration,
SType,
SymbologyResolution,
)

DBN_ENUMS: Final = (
Compression,
Encoding,
Schema,
SType,
)


@pytest.mark.parametrize(
"enum_type",
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, int)),
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, int)),
)
def test_int_enum_string_coercion(enum_type: type[Enum]) -> None:
"""
Expand All @@ -62,7 +67,7 @@ def test_int_enum_string_coercion(enum_type: type[Enum]) -> None:

@pytest.mark.parametrize(
"enum_type",
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, str)),
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, str)),
)
def test_str_enum_case_coercion(enum_type: type[Enum]) -> None:
"""
Expand All @@ -81,7 +86,7 @@ def test_str_enum_case_coercion(enum_type: type[Enum]) -> None:

@pytest.mark.parametrize(
"enum_type",
DATABENTO_ENUMS,
NATIVE_ENUMS,
)
def test_enum_name_coercion(enum_type: type[Enum]) -> None:
"""
Expand Down Expand Up @@ -109,7 +114,34 @@ def test_enum_name_coercion(enum_type: type[Enum]) -> None:

@pytest.mark.parametrize(
"enum_type",
(pytest.param(enum) for enum in DATABENTO_ENUMS),
DBN_ENUMS,
)
def test_dbn_enum_name_coercion(enum_type: type[Enum]) -> None:
"""
Test that DBN enums can be coerced from the member names.
This includes case and dash conversion to underscores.
"""
# Arrange, Act
if enum_type in (Compression, Encoding, Schema, SType):
enum_it = iter(enum_type.variants()) # type: ignore [attr-defined]
else:
enum_it = iter(enum_type)

# Assert
for enum in enum_it:
assert enum == enum_type(enum.name)
assert enum == enum_type(enum.name.replace("_", "-"))
assert enum == enum_type(enum.name.lower())
assert enum == enum_type(enum.name.upper())
with pytest.raises(DBNError):
enum_type("bar") # sanity


@pytest.mark.parametrize(
"enum_type",
(pytest.param(enum) for enum in NATIVE_ENUMS),
)
def test_enum_none_not_coercible(enum_type: type[Enum]) -> None:
"""
Expand All @@ -129,7 +161,24 @@ def test_enum_none_not_coercible(enum_type: type[Enum]) -> None:

@pytest.mark.parametrize(
"enum_type",
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, int)),
(pytest.param(enum) for enum in DBN_ENUMS),
)
def test_dbn_enum_none_not_coercible(enum_type: type[Enum]) -> None:
"""
Test that None type is not coercible and raises a TypeError.
"""
# Arrange, Act
if enum_type == Compression:
enum_type(None)
else:
# Assert
with pytest.raises(DBNError):
enum_type(None)


@pytest.mark.parametrize(
"enum_type",
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, int)),
)
def test_int_enum_stringy_mixin(enum_type: type[Enum]) -> None:
"""
Expand All @@ -149,7 +198,7 @@ def test_int_enum_stringy_mixin(enum_type: type[Enum]) -> None:

@pytest.mark.parametrize(
"enum_type",
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, str)),
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, str)),
)
def test_str_enum_stringy_mixin(enum_type: type[Enum]) -> None:
"""
Expand All @@ -169,7 +218,7 @@ def test_str_enum_stringy_mixin(enum_type: type[Enum]) -> None:

@pytest.mark.parametrize(
"enum_type",
(pytest.param(enum) for enum in DATABENTO_ENUMS if issubclass(enum, Flag)),
(pytest.param(enum) for enum in NATIVE_ENUMS if issubclass(enum, Flag)),
)
def test_int_flags_stringy_mixin(enum_type: type[Flag]) -> None:
"""
Expand Down

0 comments on commit 7215e0e

Please sign in to comment.