Skip to content

Commit

Permalink
Fix composable loop reinit bug (#127)
Browse files Browse the repository at this point in the history
* Fix loop reinit bug

* Add infinite loop test

* Bump version
  • Loading branch information
MaxSchambach authored Jun 22, 2023
1 parent 15dd10d commit 6201509
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "squirrel-core"
version = "0.19.0"
version = "0.19.1"
description = "Squirrel is a Python library that enables ML teams to share, load, and transform data in a collaborative, flexible and efficient way."
authors = ["Merantix Momentum"]
license = "Apache 2.0"
Expand Down
2 changes: 1 addition & 1 deletion squirrel/iterstream/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def __iter__(self) -> t.Iterator:
except StopIteration:
if not _started:
return
current_ = iter(deepcopy(self.source))
current_ = iter(deepcopy(self.source))
else:
for _ in range(self.n):
yield from iter(deepcopy(self.source))
Expand Down
11 changes: 11 additions & 0 deletions test/test_iterstream/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ def test_loop(samples: t.List[SampleType], n: int) -> None:
assert IterableSource([1, 2, 3]).loop(3).collect() == [1, 2, 3, 1, 2, 3, 1, 2, 3]


def test_loop_infinite() -> None:
"""Test infinite loop"""
it = IterableSource([1, 2, 3]).loop()
data = []
for i, x in enumerate(it):
data.append(x)
if i == 8:
break
assert data == [1, 2, 3, 1, 2, 3, 1, 2, 3]


def test_take_side_effect() -> None:
"""Test that take_ fetches correct number of elements from an iterator."""
lst = [1, 2, 3, 4]
Expand Down

0 comments on commit 6201509

Please sign in to comment.