Skip to content

getattributes(::DimArray): always a Dict with String keys - #70

Open
bjarthur wants to merge 1 commit into
JuliaDataCubes:masterfrom
bjarthur:bja/dimarray-attributes
Open

bjarthur wants to merge 1 commit into
JuliaDataCubes:masterfrom
bjarthur:bja/dimarray-attributes

Conversation

@bjarthur

@bjarthur bjarthur commented Oct 6, 2026

Copy link
Copy Markdown

The axis interface says getattributes returns a Dict keyed by Strings. For a DimArray the DimensionalData extension returned metadata(x) as is, which is NoMetadata() for an array built without metadata, or a Metadata wrapper, or a Dict keyed by Symbols.

Downstream, YAXArrays stores that object as the YAXArray's properties, and savedataset then fails with MethodError: no method matching copy(::NoMetadata). Users work around it by constructing the DimArray with metadata = Dict{String,Any}() (see JuliaDataCubes/YAXArrays.jl#362 and its MWE).

This normalises the three cases to Dict{String,Any}: NoMetadata to an empty Dict, a Metadata wrapper to its Dict, and any AbstractDict to one with String keys. Anything else is passed through unchanged.

julia> using YAXArrayBase, DimensionalData
julia> getattributes(DimArray(rand(2, 3), (X(1:2), Y(1:3))))
# before: NoMetadata()          after: Dict{String, Any}()
julia> getattributes(DimArray(rand(2, 3), (X(1:2), Y(1:3)); metadata = Dict(:units => "K")))
# before: Dict(:units => "K")   after: Dict{String, Any}("units" => "K")

Tests added to the DimensionalData test item for all three cases.

🤖 Generated with Claude Code

The axis interface promises getattributes returns a Dict keyed by Strings.
For a DimArray it returned DimensionalData's metadata as is: NoMetadata() for
an array built without metadata, or a Metadata wrapper, or a Dict keyed by
Symbols. Downstream, YAXArrays stored that as the YAXArray's properties and
savedataset failed on copy(::NoMetadata); users worked around it with
`metadata = Dict{String,Any}()` (JuliaDataCubes/YAXArrays.jl#362). Normalise
all three to Dict{String,Any}; anything else is passed through unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant