JuliaPhysics / JuliaPhysics/DynamicQuantities.jl
`dimension` fetches fist item of `AbstractArray` even if empty
- Dominant language
- Julia
- Stars
- 155
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
While wrapping `QuantityArray`s with `KeyedArray` from [`AxisKeys.jl`](https://github.com/mcabbott/AxisKeys.jl), I met an edge case of `dimension` with empty arrays.
```julia
] activate --temp
] add AxisKeys
] add DynamicQuantities
A = KeyedArray(QuantityArray(Matrix{Float64}(undef,0,6),us"s"); time = Float64[], channel = ["$i" for i in 1:6])
dimension(A)
```
This throws
```
julia> dimension(A)
ERROR: BoundsError: attempt to access 0×6 NamedDimsArray(QuantityArray(::Matrix{Float64}, ::Quantity{Float64, SymbolicDimensions{FRInt32}}), (:time, :channel)) at index [1]
Stacktrace:
[1] throw_boundserror(A::NamedDimsArray{(:time, :channel), Quantity{…}, 2, QuantityArray{…}}, I::Tuple{Int64})
@ Base .\essentials.jl:15
[2] checkbounds
@ .\abstractarray.jl:699 [inlined]
[3] getindex
@ D:\bamboo\.julia\packages\AxisKeys\a6h2b\src\struct.jl:76 [inlined]
[4] first
@ .\abstractarray.jl:452 [inlined]
[5] dimension(aq::KeyedArray{Quantity{…}, 2, NamedDimsArray{…}, Tuple{…}})
@ DynamicQuantities D:\bamboo\.julia\packages\DynamicQuantities\wqpWc\src\utils.jl:442
[6] top-level scope
@ REPL[26]:1
Some type information was truncated. Use `show(err)` to see complete types.
```
at https://github.com/JuliaPhysics/DynamicQuantities.jl/blob/f619e165815124d66be7135c495352f769afcdc8/src/utils.jl#L442
I am not sure how this should be circumvented. If the array is empty, it is obvious that all elements should be of the same type. It may require an additional dispatch.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.