-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not truncate zip inputs #20499
Comments
I believe that truncation is generally useful for combining infinite iterators with finite ones. I do agree that if two finite iterators have different lengths, an error is better. |
Duplicate of #17928? |
I would close that one in favor of this since that was a specific confusing case, whereas this is explicitly a decision issue about whether the underlying general behavior is a good idea or not. |
A similar issue arises from My gut feeling is that if all the iterators have lengths ( |
I think that we should be even stricter and only allow truncation of infinite streams. Or does !haslength mean that a stream is infinite? I would interpret it as having unknown length, but I may be misunderstanding the trait. |
No, you're right, !haslength just means the length is unknown. But what if you want to do something like zip the line iterators of two files, deciding whether to stop as you go? That should be allowed. |
Yes, fair enough, although it might be better to opt into that sort of thing somehow. |
I feel like providing both |
It might be nice to provide a keyword argument to Since we allow isbits values for type parameters, perhaps we could even parameterize Anyway, just an idea. |
I would spell that keyword out fully, otherwise it kind of looks like you want to apply the |
I think we should fix this for 0.7. See #25583 for a problematic illustration. |
I believe this is only a problem with |
My feeling is that both
|
I continue to find it hard to see why truncating zip is a problem. Maybe part of the reason is that iterators are inherently lazy; by design you can take as much or as little from an iterator as you want. So it seems weird for it to be an error not to consume all of an iterator. This thread is very short on real, compelling arguments. I see an "I would much prefer" and a "gut feeling", and not much more than that. So I remain opposed to this change. |
The rationale is that if
|
In my view, that's because |
Triage: we're already getting late in the game here and there are significant design and feasibility questions about how to even make this require same length without breaking things. Python and Lisp have the same truncating behavior as we have now, so this seems like it can't be that bad. |
If it was decided to truncate zip, then why in some cases it gives error? julia> collect(zip(1:3, 2:5))
ERROR: DimensionMismatch("dimensions must match")
julia> [i for i in zip(1:3, 2:5)]
ERROR: DimensionMismatch("dimensions must match")
julia> for i in zip(1:3, 2:5)
@show i
end
i = (1, 2)
i = (2, 3)
i = (3, 4)
julia> length(zip(1:3, 2:5))
3 Same issue was raised here #17928, but was closed as duplicate, which it isn't. |
FYI: Python considers it a
I saw in other issue: "Triage decided not to throw an error when zip is passed arguments with different lengths", I guess referring to Jeff removing triage, and Stefan closing. It's not too late to do as Python, optional, but is too late to error different lengths? |
Like Python, Julia's
zip(a, b)
ignores the tail end of its input sequences when they are of unequal length (but see #17928). I've yet to encounter a problem where I wanted that behavior, and I would much prefer seeing an error when the inputs are of unequal length. Are there applications where truncation is very convenient?The text was updated successfully, but these errors were encountered: