Skip to content

Commit 7b359b6

Browse files
committed
FIX: Bug in bento iteration
1 parent efd99e2 commit 7b359b6

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

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:

tests/test_historical_bento.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ def test_bento_iterable() -> None:
621621
"22993, 1170352)"
622622
)
623623
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)"
624+
str(record_list[1]) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, "
625+
"3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, "
626+
"19621, 1170353)"
627627
)
628628

629629

@@ -651,14 +651,14 @@ def test_bento_iterable_parallel() -> None:
651651
"22993, 1170352)"
652652
)
653653
assert (
654-
str(next(second)) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
655-
"3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
656-
"22993, 1170352)"
654+
str(next(second)) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, "
655+
"3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, "
656+
"19621, 1170353)"
657657
)
658658
assert (
659-
str(next(first)) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
660-
"3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
661-
"22993, 1170352)"
659+
str(next(first)) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, "
660+
"3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, "
661+
"19621, 1170353)"
662662
)
663663

664664

0 commit comments

Comments
 (0)