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

Feature Request: Rational index should be interpreted categorically #181

Open
fredcallaway opened this issue May 21, 2020 · 2 comments
Open

Comments

@fredcallaway
Copy link

fredcallaway commented May 21, 2020

Example:

julia> x = AxisArray(rand(3), foo=[1//2, 1//3, 1//4])
julia> x[foo=atvalue(1//2)]
ERROR: BoundsError: attempt to access 3-element Array{Rational{Int64},1} at index [TolValue(1//2, tol=0//1)]

Seems to me that this should work the same way it does for symbols.

@mcabbott
Copy link
Contributor

This seems like a bug to me, since it has an explicit atvalue. Compare:

julia> z = AxisArray(rand(3), sy=[:a, :b, :c]);

julia> z[atvalue(:b)] # explicit
0.5205382494635875

julia> z[:b] # this can guess based on type
0.5205382494635875

julia> y = AxisArray(rand(3), bar=[10,20,30]);

julia> y[atvalue(20)] # explicit
0.6526959443703837

julia> y[20] # interpreted as an index
ERROR: BoundsError: attempt to access 3-element Array{Float64,1} at index [20]

Rewrites without the bug:

julia> using DimensionalData

julia> d = DimensionalArray(rand(3), Dim{:foo}([1//2, 1//3, 1//4]));

julia> d[Dim{:foo} <| At(1//3)]
0.8922925051403834

julia> using AxisKeys

julia> k = KeyedArray(rand(3), foo=[1//2, 1//3, 1//4]);

julia> k[foo = Key(1//3)]
0.8963527992711511

julia> k(foo = 1//3)
0.8963527992711511

@fredcallaway
Copy link
Author

@mcabbott Ah the growing pains of a new language... AxisKeys looks great, will give that a shot.

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