rafaqz / DimensionalData.jl

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

LookupArrays.order does not work on Dimension with Vector of String #626

Open felixcremer opened 7 months ago

felixcremer commented 7 months ago

I would have expected to get Unordered() back from that call based on the docstring.

julia> dim = Dim{:Colors}(["Red", "Blue", "Green"])
Dim{:Colors} String["Red", "Blue", "Green"]

julia> DimensionalData.Dimensions.LookupArrays.order(dim)
ERROR: MethodError: no method matching order(::Vector{String})

Closest candidates are:
  order(::DimTable, Any...)
   @ DimensionalData ~/.julia/packages/DimensionalData/R7veM/src/tables.jl:224
  order(::Tuple{})
   @ DimensionalData ~/.julia/packages/DimensionalData/R7veM/src/Dimensions/dimension.jl:229
  order(::DimensionalData.Dimensions.LookupArrays.AbstractCategorical)
   @ DimensionalData ~/.julia/packages/DimensionalData/R7veM/src/LookupArrays/lookup_arrays.jl:444
  ...

Stacktrace:
 [1] order(dim::Dim{:Colors, Vector{String}})
   @ DimensionalData.Dimensions ~/.julia/packages/DimensionalData/R7veM/src/Dimensions/dimension.jl:223
 [2] top-level scope
   @ REPL[134]:1
rafaqz commented 7 months ago

The dimension has to pass through a format call before any of that works, as happens in DimArray construction.

We cant do it on Dimension construction because its not always type-stable or cost-free, and Dimensions are used to wrap heaps of things besides LookupArray.

I guess we could make these functions call format ? its currently all a bit obscure how the type detection actually works...

rafaqz commented 6 months ago

BTW what is the use-case for this?

felixcremer commented 6 months ago

I cant remember. I was debugging something and got surprised by this. I think we could clarify the docstring and then close it.