Skip to content

Commit

Permalink
Fix one-off edge case in split_lazy (#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
pzelasko committed May 31, 2024
1 parent c778520 commit c1d4432
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lhotse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,13 @@ def split_manifest_lazy(
if prefix == "":
prefix = "split"

items = iter(it)
split_idx = start_idx
splits = []
items = iter(it)
try:
item = next(items)
except StopIteration:
return splits
while True:
try:
written = 0
Expand All @@ -321,9 +325,9 @@ def split_manifest_lazy(
(output_dir / prefix).with_suffix(f".{idx}.jsonl.gz")
) as writer:
while written < chunk_size:
item = next(items)
writer.write(item)
written += 1
item = next(items)
split_idx += 1
except StopIteration:
break
Expand Down
11 changes: 11 additions & 0 deletions test/test_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def test_split_lazy_even(manifest_type):
)


def test_split_lazy_edge_case_extra_shard(tmp_path):
N = 512
chsz = 32
nshrd = 16
manifest = DummyManifest(CutSet, begin_id=0, end_id=N - 1)
manifest_subsets = manifest.split_lazy(output_dir=tmp_path, chunk_size=chsz)
assert len(manifest_subsets) == nshrd
for item in sorted(tmp_path.glob("*")):
print(item)


@mark.parametrize("manifest_type", [RecordingSet, SupervisionSet, FeatureSet, CutSet])
def test_combine(manifest_type):
expected = DummyManifest(manifest_type, begin_id=0, end_id=200)
Expand Down

0 comments on commit c1d4432

Please sign in to comment.