JuliaArrays / AxisArrays.jl

Performant arrays where each dimension can have a named axis with values
http://JuliaArrays.github.io/AxisArrays.jl/latest/
Other
200 stars 41 forks source link

Select by axis values doesn't preserve the order #182

Open wytbella opened 4 years ago

wytbella commented 4 years ago

When selecting an AxisArray by index, it returns the correct order as expected. However, if one selects by axis values, it doesn’t preserve the order (see example below).

julia> tmp = AxisArray(rand(2,3), x=[:a, :b], y=[:A, :B, :C])
2-dimensional AxisArray{Float64,2,...} with axes:
    :x, [:a, :b]
    :y, [:A, :B, :C]
And data, a 2×3 Array{Float64,2}:
 0.373003  0.355006  0.158701
 0.691354  0.277119  0.651728
julia> tmp[[2,1],:]
2-dimensional AxisArray{Float64,2,...} with axes:
    :x, [:b, :a]
    :y, [:A, :B, :C]
And data, a 2×3 Array{Float64,2}:
 0.691354  0.277119  0.651728
 0.373003  0.355006  0.158701
julia> tmp[[:b, :a],:]
2-dimensional AxisArray{Float64,2,...} with axes:
    :x, [:a, :b]
    :y, [:A, :B, :C]
And data, a 2×3 Array{Float64,2}:
 0.373003  0.355006  0.158701
 0.691354  0.277119  0.651728
mcabbott commented 4 years ago

And worse if you repeat them:

julia> tmp[[2, 1, 1], :]
2-dimensional AxisArray{Float64,2,...} with axes:
    :x, [:b, :a, :a]
    :y, [:A, :B, :C]
And data, a 3×3 Array{Float64,2}:
 0.352127  0.787136  0.725084
 0.521467  0.939554  0.828499
 0.521467  0.939554  0.828499

julia> tmp[[:b, :a, :a], :]
ERROR: ArgumentError: index Symbol[] not found
Stacktrace:
 [1] axisindexes(::Type{AxisArrays.Categorical}, ::Array{Symbol,1}, ::Array{Symbol,1}) at /Users/me/.julia/packages/AxisArrays/IFpjG/src/indexing.jl:329