Repository navigation
Conversation
… yaxcreate
yaxconvert reduces a source array to dimension names and values, so a target
that models dimensions as types, DimensionalData, has to rebuild every axis as
Dim{name}(values): a DimArray with a user's `@dim D1` converts to one with
Dim{:D1} (JuliaDataCubes/YAXArrays.jl#362).
Add an optional interface function `dimtype(x, i)`, the dimension type of axis
i or `nothing` when the source has only a name (the fallback), and a
six-argument `yaxcreate(T, data, dnames, dtypes, dvals, attributes)` that
yaxconvert now calls; its default forwards to the five-argument method, so
targets that do not model dimension types are unchanged. The DimensionalData
extension defines dimtype(::DimArray, i) as basetypeof(dims(x)[i]) and builds
axes as dtypes[i](dvals[i]) when a type is given.
This is the interface-level alternative to the direct DimArray <-> YAXArray
methods proposed in JuliaDataCubes/YAXArrays.jl#626.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
bjarthur
marked this pull request as draft
October 6, 2026 21:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the alternative to JuliaDataCubes/YAXArrays.jl#626 described in this comment there, implemented so that the two approaches to JuliaDataCubes/YAXArrays.jl#362 can be compared as code. One of the two should be taken, not both.
Problem
yaxconvertreduces a source array to dimension names and values and hands them toyaxcreate(T, data, dnames, dvals, attrs). A target that models dimensions as types, DimensionalData, has nothing to go on but the name, so it rebuilds every axis asDim{name}(values): aDimArraywith a user's@dim D1converts to one withDim{:D1}, andX,TibecomeDim{:X},Dim{:Ti}.Change
dimtype(x, i): the dimension type of axisi, ornothingwhen the source only has a name (the fallback, so nothing changes for existing implementers). The DimensionalData extension defines it asDimensionalData.basetypeof(dims(x)[i]), which givesD1for aD1,Xfor anX,Dim{:lon}for aDim{:lon}.yaxconvertnow calls a six-argumentyaxcreate(T, data, dnames, dtypes, dvals, attrs). Its default forwards to the five-argument method, so targets that do not model dimension types (AxisArrays, NamedDims, KeyedArray, NamedTuple) are untouched. The DimensionalData extension implements it asdtypes[i] === nothing ? Dim{dnames[i]}(dvals[i]) : dtypes[i](dvals[i]).dimtypeis exported alongsidedimnameanddimvals.The YAXArrays side (defining
dimtype(::YAXArray, i)and the six-argumentyaxcreate(::Type{YAXArray}, ...)) is in JuliaDataCubes/YAXArrays.jl#TBD, which needs this released first.Compared with the direct methods in YAXArrays#626
That PR adds
yaxconvert(::Type{YAXArray}, ::AbstractDimArray)andyaxconvert(::Type{<:DimArray}, ::YAXArray)passing theDimensionobjects through, in YAXArrays alone. This one extends the protocol so any source that can supply dimension types has them preserved through the shared pipeline. Trade-offs: the direct methods also keep lookups (SampledvsCategorical, order, span) and metadata exactly, which this still rebuilds from values; this one touches the public interface and needs a release before YAXArrays can use it, but has no special case for a pair of types. Only DimensionalData-based sources carry dimension types today, so the two are equivalent in what they fix.Metadata normalisation (
NoMetadatato aDict) is a separate defect handled by #70 either way.Tests
The DimensionalData test item checks
dimtypeon a plain source (nothing) and on aDimArray(D1,X), that aDimArrayround trip throughyaxconvertkeepstypeof(dims(...)), and that the plain-array conversion still producesDim{:x}axes.🤖 Generated with Claude Code