`map` fails with `QuantityArray`
jkrumbiegel opened this issue · 3 comments
jkrumbiegel commented
julia> map(identity, [us"hr"])
1-element Vector{DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}:
1.0 hr
julia> map(identity, QuantityArray([us"hr"]))
ERROR: TypeError: in typeassert, expected AbstractVector{<:DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}, got a value of type QuantityArray{DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, 1, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}, DynamicQuantities.Quantity{DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, Vector{DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}}
Stacktrace:
[1] _collect(c::QuantityArray{Float64, 1, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}, DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, Vector{Float64}}, itr::Base.Generator{QuantityArray{Float64, 1, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}, DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, Vector{Float64}}, typeof(identity)}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
@ Base ./array.jl:812
[2] collect_similar(cont::QuantityArray{Float64, 1, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}, DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, Vector{Float64}}, itr::Base.Generator{QuantityArray{Float64, 1, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}, DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, Vector{Float64}}, typeof(identity)})
@ Base ./array.jl:711
[3] map(f::Function, A::QuantityArray{Float64, 1, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}, DynamicQuantities.Quantity{Float64, SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}}, Vector{Float64}})
@ Base ./abstractarray.jl:3263
[4] top-level scope
@ REPL[92]:1
version is [06fc5a27] DynamicQuantities v0.10.0
MilesCranmer commented
Thanks for this! Very strange. I wonder what method we need to overload here?
gaurav-arya commented
QuantityArray
's feel somewhat similar to StructArray
s in the sense that both construct the struct on the fly in getindex
, so I'm wondering (without much knowledge at all of the details) if templating off https://github.com/JuliaArrays/StructArrays.jl/blob/99f05561cab19fb23f478a12a8429764871ccff3/src/structarray.jl would make sense in terms of getting the logic correct?
MilesCranmer commented
Fixed with #95
Sorry just saw your comment @gaurav-arya. I think that's a good idea!