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>
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 52.22%. Comparing base (49d7155) to head (7e9c6c0).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
ext/DimensionalDataExt.jl 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #70      +/-   ##
==========================================
+ Coverage   52.04%   52.22%   +0.18%     
==========================================
  Files          12       12              
  Lines         490      494       +4     
==========================================
+ Hits          255      258       +3     
- Misses        235      236       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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