Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yaxconvert alters the dim names #362

Open
bjarthur opened this issue Jan 19, 2024 · 2 comments
Open

yaxconvert alters the dim names #362

bjarthur opened this issue Jan 19, 2024 · 2 comments

Comments

@bjarthur
Copy link

why the change from D1, D2 here to Dim{:D1}, Dim{:D2} when converting a dimarray to a yaxarray?

julia> using DimensionalData, YAXArrays, YAXArrayBase

julia> DimensionalData.@dim D1

julia> DimensionalData.@dim D2

julia> dd = rand(D1(["a","b"]), D2(["x","y"]), metadata = Dict{String, Any}())
2×2 DimArray{Float64,2} with dimensions: 
  D1 Categorical{String} String["a", "b"] ForwardOrdered,
  D2 Categorical{String} String["x", "y"] ForwardOrdered
        "x"       "y"
  "a"  0.790863  0.345696
  "b"  0.490964  0.814311

julia> ddyax = yaxconvert(YAXArray, dd)
2×2 YAXArray{Float64,2} with dimensions: 
  Dim{:D1} Categorical{String} String["a", "b"] ForwardOrdered,
  Dim{:D2} Categorical{String} String["x", "y"] ForwardOrdered
Total size: 32.0 bytes

same thing happens in the other direction, yax to dd:

julia> yax = YAXArray((D1(["a","b"]), D2(["x","y"])), rand(2,2))
2×2 YAXArray{Float64,2} with dimensions: 
  D1 Categorical{String} String["a", "b"] ForwardOrdered,
  D2 Categorical{String} String["x", "y"] ForwardOrdered
Total size: 32.0 bytes


julia> yaxdd = yaxconvert(DimArray, yax)
2×2 DimArray{Float64,2} with dimensions: 
  Dim{:D1} Categorical{String} String["a", "b"] ForwardOrdered,
  Dim{:D2} Categorical{String} String["x", "y"] ForwardOrdered
        "x"       "y"
  "a"  0.27363   0.455353
  "b"  0.446381  0.709265

there is a workaround, but why doesn't yaxconvert operate like this?

julia> hack = DimArray(yax.data, dims(yax))
2×2 DimArray{Float64,2} with dimensions: 
  D1 Categorical{String} String["a", "b"] ForwardOrdered,
  D2 Categorical{String} String["x", "y"] ForwardOrdered
        "x"       "y"
  "a"  0.27363   0.455353
  "b"  0.446381  0.709265

i ask because indexing with D1 is more succinct and easier to read and type than Dim{:D1}.

@lazarusA
Copy link
Collaborator

lazarusA commented Jan 19, 2024

most likely is because currently there is not a @dim definition as in DimensionalData.@dim D1 . I agree that is annoying, suggestions [PRs] are welcome.

@felixcremer
Copy link
Member

The construction of the DimArray or Yaxarray in yaxcreate in YAXArrayBase is using the Dim Constructor explicitely. There might be a smarter way to get the Dimension from a dimension name.

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

No branches or pull requests

3 participants