Skip to content
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

UnorderedDictionary with more keys than values doesn't throw #156

Open
jariji opened this issue Jan 15, 2025 · 3 comments
Open

UnorderedDictionary with more keys than values doesn't throw #156

jariji opened this issue Jan 15, 2025 · 3 comments

Comments

@jariji
Copy link

jariji commented Jan 15, 2025

I expected this to throw an exception.

julia> Dictionary(['a', 'b'], [1])
ERROR: AssertionError: length(values) == length(_values(inds))

julia> UnorderedDictionary(['a', 'b'], [1])
1-element UnorderedDictionary{Char, Int64}
 'a'1
@andyferris
Copy link
Owner

Okay, this one is because internally we use zip and iterate that.

Originally zip would error out when the collections had different lengths, but now it is more forgiving (I would have preferred introducing a new funciton, but there you go). Perhaps being this forgiving here would only encourage mistakes.

We should probably fix this by comparing the lengths of the inputs (but only if the iterators possess the HasLength trait...)

@jariji
Copy link
Author

jariji commented Jan 16, 2025

We should probably fix this by comparing the lengths of the inputs (but only if the iterators possess the HasLength trait...)

I think if length(collect(x)) != length(collect(y)) then UnorderedDictionary(x,y) should still error even if x or y doesn't HasLength.

@andyferris
Copy link
Owner

For sure - we can just do that check a little earlier with HasLength than without.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants