rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
269 stars 37 forks source link

`cat` return type sensitive to vector type of lookup #581

Closed sethaxen closed 5 months ago

sethaxen commented 8 months ago

In the below example, whether or not cat produces a DimArray depends on the type of vector the two Dim{:a} objects wrap. When they're matched, cating on a new dimension successfully produces a DimArray, but when they're equivalent but created differently, then cat falls back to returning a Matrix:

julia> using DimensionalData

julia> x1 = DimArray(randn(2), Dim{:a}(1:2));

julia> x2 = DimArray(randn(2), Dim{:a}([1, 2]));

julia> cat(x1, x1; dims=Dim{:b}(1:2))  # fine
2×2 DimArray{Float64,2} with dimensions: 
  Dim{:a} Sampled{Int64} 1:2 ForwardOrdered Regular Points,
  Dim{:b} Sampled{Int64} 1:2 ForwardOrdered Regular Points
     1         2
 1  -1.22968  -1.22968
 2   1.0081    1.0081

julia> cat(x2, x2; dims=Dim{:b}(1:2))  # fine
2×2 DimArray{Float64,2} with dimensions: 
  Dim{:a} Sampled{Int64} Int64[1, 2] ForwardOrdered Irregular Points,
  Dim{:b} Sampled{Int64} 1:2 ForwardOrdered Regular Points
     1          2
 1  -1.00755   -1.00755
 2   0.917128   0.917128

julia> cat(x1, x2; dims=Dim{:b}(1:2))
┌ Warning: Lookup values for Dim{:a} of [1, 2] and [1, 2] do not match. Can't `cat` AbstractDimArray, applying to `parent` object.
└ @ DimensionalData.Dimensions ~/.julia/packages/DimensionalData/lbGZS/src/Dimensions/primitives.jl:733
2×2 Matrix{Float64}:
 -1.22968  -1.00755
  1.0081    0.917128
rafaqz commented 8 months ago

Ok probably we are chrcking the lookup type and that doesnt totally make sense.

So we need to check the wrapper and order/sampling etc separately but not the parent array type.