-
Notifications
You must be signed in to change notification settings - Fork 311
zip_broadcast(strict=True) fails if the leftmost iterables are exactly 1 item longer than the others #561
Copy link
Copy link
Closed
Labels
bugpr-welcomeWe are open to PRs that fix this issue - leave a note if you're working on it!We are open to PRs that fix this issue - leave a note if you're working on it!
Description
Here's the bug:
>>> import more_itertools as mi
>>> mi.__version__
'8.10.0'
>>> list(mi.zip_broadcast([1, 2], [3], strict=True))
[(1, 3)]
>>> list(mi.zip_broadcast([1, 2], [3], [4], strict=True))
[(1, 3, 4)]
>>> list(mi.zip_broadcast([1, 2], [3, 4], [5], strict=True))
[(1, 3, 5)]
Here are some cases where the expected exception is raised:
>>> list(mi.zip_broadcast([1], [2, 3], strict=True))
Traceback (most recent call last):
...
more_itertools.more.UnequalIterablesError: Iterables have different lengths
>>> list(mi.zip_broadcast([1], [2, 3], [4], strict=True))
Traceback (most recent call last):
...
more_itertools.more.UnequalIterablesError: Iterables have different lengths
>>> list(mi.zip_broadcast([1], [2], [3, 4], strict=True))
Traceback (most recent call last):
...
more_itertools.more.UnequalIterablesError: Iterables have different lengths
>>> list(mi.zip_broadcast([1], [2, 3], [4, 5], strict=True))
Traceback (most recent call last):
...
more_itertools.more.UnequalIterablesError: Iterables have different lengths
>>> list(mi.zip_broadcast([1, 2], [3], [4, 5], strict=True))
Traceback (most recent call last):
...
more_itertools.more.UnequalIterablesError: Iterables have different lengths
I think the problem is that zip() consumes extra elements from the iterables given to it, so checking which iterables have been exhausted after calling zip() is unreliable. I don't see an easy way to fix this, but the implementation I provided in #543 does handle these cases correctly.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugpr-welcomeWe are open to PRs that fix this issue - leave a note if you're working on it!We are open to PRs that fix this issue - leave a note if you're working on it!