Skip to content

Commit 9d11f15

Browse files
authored
VER: Release 0.8.1
## 0.8.1 - 2023-03-05 - Fixed bug in `Bento` iteration where multiple readers were created - Added `from_dbn` convenience alias for loading DBN files
2 parents 3eac4af + d93c7de commit 9d11f15

File tree

6 files changed

+50
-16
lines changed

6 files changed

+50
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Changelog
22

3+
## 0.8.1 - 2023-03-05
4+
- Fixed bug in `Bento` iteration where multiple readers were created
5+
- Added `from_dbn` convenience alias for loading DBN files
6+
37
## 0.8.0 - 2023-03-03
4-
- Integrate DBN encoding `0.3.2`
8+
- Integrated DBN encoding `0.3.2`
59
- Renamed `timeseries.stream` to `timeseries.get_range`
610
- Renamed `timeseries.stream_async` to `timeseries.get_range_async`
711
- Deprecated `timeseries.stream(...)` method

databento/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@
5454

5555
# Set to either 'DEBUG' or 'INFO', controls console logging
5656
log: Optional[str] = None
57+
58+
# Convenience imports
59+
from_dbn = Bento.from_file

databento/common/bento.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,10 @@ def __init__(self, data_source: DataSource) -> None:
346346
] = {}
347347

348348
def __iter__(self) -> Generator[np.void, None, None]:
349+
reader = self.reader
349350
for _ in range(self.record_count):
350-
raw = self.reader.read(self.record_size)
351+
raw = reader.read(self.record_size)
351352
rec = np.frombuffer(raw, dtype=STRUCT_MAP[self.schema])
352-
if rec.size == 0:
353-
raise StopIteration
354353
yield rec[0]
355354

356355
def _apply_pretty_ts(self, df: pd.DataFrame) -> pd.DataFrame:

databento/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.8.0"
1+
__version__ = "0.8.1"

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mypy>=0.991
1+
mypy>=1.0.1
22
pytest>=7.2.0
33
pytest-mock>=3.10.0
44
types-requests

tests/test_historical_bento.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import collections
12
import datetime as dt
23
import sys
34
from pathlib import Path
45
from typing import List, Tuple, Union
56

7+
import databento
68
import numpy as np
79
import pandas as pd
810
import pytest
@@ -184,6 +186,18 @@ def test_to_ndarray_with_stub_data_returns_expected_array() -> None:
184186
)
185187

186188

189+
def test_iterator_produces_expected_data() -> None:
190+
# Arrange
191+
stub_data = get_test_data(schema=Schema.MBO)
192+
data = Bento.from_bytes(data=stub_data)
193+
194+
# Act (consume iterator)
195+
handler = collections.deque(data)
196+
197+
# Assert
198+
assert len(handler) == 2
199+
200+
187201
def test_replay_with_stub_data_record_passes_to_callback() -> None:
188202
# Arrange
189203
stub_data = get_test_data(schema=Schema.MBO)
@@ -372,14 +386,28 @@ def test_to_df_with_pretty_px_with_various_schemas_converts_prices_as_expected(
372386
def test_from_file_given_various_paths_returns_expected_metadata(
373387
expected_schema: Schema,
374388
) -> None:
375-
# Arrange, Act
389+
# Arrange
376390
path = get_test_data_path(schema=expected_schema)
391+
392+
# Act
377393
data = Bento.from_file(path=path)
378394

379395
# Assert
380396
assert data.schema == expected_schema
381397

382398

399+
def test_from_dbn_alias() -> None:
400+
# Arrange
401+
path = get_test_data_path(schema=Schema.MBO)
402+
403+
# Act
404+
data = databento.from_dbn(path=path)
405+
406+
# Assert
407+
assert data.schema == Schema.MBO
408+
assert data.record_count == 2
409+
410+
383411
def test_mbo_to_csv_writes_expected_file_to_disk(tmp_path: Path) -> None:
384412
# Arrange
385413
test_data_path = get_test_data_path(schema=Schema.MBO)
@@ -621,9 +649,9 @@ def test_bento_iterable() -> None:
621649
"22993, 1170352)"
622650
)
623651
assert (
624-
str(record_list[1]) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
625-
"3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
626-
"22993, 1170352)"
652+
str(record_list[1]) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, "
653+
"3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, "
654+
"19621, 1170353)"
627655
)
628656

629657

@@ -651,14 +679,14 @@ def test_bento_iterable_parallel() -> None:
651679
"22993, 1170352)"
652680
)
653681
assert (
654-
str(next(second)) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
655-
"3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
656-
"22993, 1170352)"
682+
str(next(second)) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, "
683+
"3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, "
684+
"19621, 1170353)"
657685
)
658686
assert (
659-
str(next(first)) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
660-
"3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
661-
"22993, 1170352)"
687+
str(next(first)) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, "
688+
"3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, "
689+
"19621, 1170353)"
662690
)
663691

664692

0 commit comments

Comments
 (0)