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

Selecting fails with vector #104

Open
aplavin opened this issue Mar 9, 2022 · 3 comments
Open

Selecting fails with vector #104

aplavin opened this issue Mar 9, 2022 · 3 comments

Comments

@aplavin
Copy link
Collaborator

aplavin commented Mar 9, 2022

Somehow, behavior for key-based selections differs between ranges and vectors. Selecting with vectors fails when some of the keys are not found:

julia> ka = KeyedArray(rand(3), x=10:12)

julia> ka(x=12:13)
1-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   x ∈ 1-element UnitRange{Int64}
And data, 1-element view(::Vector{Float64}, 3:3) with eltype Float64:
 (12)  0.8790116535631433

julia> ka(x=[12, 13])
ERROR: ArgumentError: unable to check bounds for indices of type Nothing
@aplavin
Copy link
Collaborator Author

aplavin commented Mar 9, 2022

Probably can be fixed by replacing

[findindex(x, r) for x in a]

with findall(∈(Set(a)), r), but I'm not completely sure.

@mcabbott
Copy link
Owner

mcabbott commented Mar 9, 2022

I think those should both be errors. But apparently little effort was made to check & handle them. This is an error but perhaps it should be a more helpful error:

julia> ka(x=13)
ERROR: ArgumentError: invalid index: nothing of type Nothing

@aplavin
Copy link
Collaborator Author

aplavin commented Mar 9, 2022

Interesting, I thought the intended behavior with collections (ranges/vectors) is to keep matches, drop non-matches, and don't throw anything.

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