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

broadcast_dims.(*, ..., ...) no method matching order(::Vector{Vector{Int64}}) #678

Closed
lazarusA opened this issue Mar 29, 2024 · 3 comments

Comments

@lazarusA
Copy link
Collaborator

This example used to work in a previous version (not anymore):

using DimensionalData
using YAXArrays
using Dates
using Statistics

axlist = (
    Dim{:Ti}(Date("2021-12-01"):Day(1):Date("2022-12-31")),
    X(range(1, 10, length=10)),
    Y(range(1, 5, length=15)),
    Dim{:Variable}(["var1", "var2"]))
data = rand(396, 10, 15, 2)
ds = YAXArray(axlist, data)

tempo = dims(ds, Dim{:Ti})  # Dim{:Ti} and not Ti ! a yax thing maybe.
month_length = YAXArray((tempo,), daysinmonth.(tempo))

g_tempo = groupby(month_length, Dim{:Ti} => seasons(; start=December))

sum_days = sum.(g_tempo, dims=Dim{:Ti})
weights = map(./, g_tempo, sum_days)

g_ds = groupby(ds, Dim{:Ti} => seasons(; start=December))

g_ds_w = broadcast_dims.(*, DimArray.(weights), DimArray.(g_ds))
ERROR: MethodError: no method matching order(::Vector{Vector{Int64}})

Closest candidates are:
  order(::DimTable, Any...)
   @ DimensionalData ~/.julia/packages/DimensionalData/UNpzY/src/tables.jl:169
  order(::Tuple{})
   @ DimensionalData ~/.julia/packages/DimensionalData/UNpzY/src/Dimensions/dimension.jl:231
  order(::DimensionalData.Dimensions.Lookups.NoLookup)
   @ DimensionalData ~/.julia/packages/DimensionalData/UNpzY/src/Lookups/lookup_arrays.jl:149
  ...

Stacktrace:
  [1] order(dim::Dim{:Ti, Vector{Vector{Int64}}})
    @ DimensionalData.Dimensions ~/.julia/packages/DimensionalData/UNpzY/src/Dimensions/dimension.jl:223
  [2] #_comparedims#77
    @ ~/.julia/packages/DimensionalData/UNpzY/src/Dimensions/primitives.jl:564 [inlined]
  [3] _comparedims
    @ ~/.julia/packages/DimensionalData/UNpzY/src/Dimensions/primitives.jl:557 [inlined]
  [4] _comparedims
    @ ~/.julia/packages/DimensionalData/UNpzY/src/Dimensions/primitives.jl:546 [inlined]
  [5] comparedims
    @ ~/.julia/packages/DimensionalData/UNpzY/src/Dimensions/primitives.jl:535 [inlined]
  [6] _broadcasted_dims(a::Base.Broadcast.Broadcasted{…}, bs::Base.Broadcast.Broadcasted{…})
    @ DimensionalData ~/.julia/packages/DimensionalData/UNpzY/src/array/broadcast.jl:102
  [7] _broadcasted_dims(::Base.RefValue{…}, ::Base.Broadcast.Broadcasted{…}, ::Vararg{…})
    @ DimensionalData ~/.julia/packages/DimensionalData/UNpzY/src/array/broadcast.jl:102
  [8] _broadcasted_dims(bc::Base.Broadcast.Broadcasted{…})
    @ DimensionalData ~/.julia/packages/DimensionalData/UNpzY/src/array/broadcast.jl:101
  [9] copy(bc::Base.Broadcast.Broadcasted{DimensionalData.DimensionalStyle{…}, Nothing, typeof(broadcast_dims), Tuple{…}})
    @ DimensionalData ~/.julia/packages/DimensionalData/UNpzY/src/array/broadcast.jl:37
 [10] copy(bc::Base.Broadcast.Broadcasted{DimensionalData.DimensionalStyle{…}, Tuple{…}, typeof(broadcast_dims), Tuple{…}})
    @ DimensionalData ~/.julia/packages/DimensionalData/UNpzY/src/array/broadcast.jl:39
 [11] materialize(bc::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast ./broadcast.jl:903
 [12] top-level scope
    @ ~/Documents/YAXArrays.jl/docs/test.jl:24
Some type information was truncated. Use `show(err)` to see complete types.
@rafaqz
Copy link
Owner

rafaqz commented Apr 4, 2024

There is something wrong with DimGroupbyArray. It has an eltype with N=3 but the objects are actually 4 dimensional.

julia> eltype(g_ds)
YAXArray{Float64, 3, SubArray{Float64, 3, Array{Float64, 4}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, true}, Tuple{X{Sampled{Float64, StepRan
geLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, ForwardOrdered, Regular{Float64}, Points, NoMetadata}}, Y{Sampled{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64
}, Base.TwicePrecision{Float64}, Int64}, ForwardOrdered, Regular{Float64}, Points, NoMetadata}}, Dim{:Variable, DimensionalData.Dimensions.Lookups.Categorical{String, SubArray{String, 1, Vector{String}, Tupl
e{Base.Slice{Base.OneTo{Int64}}}, true}, ForwardOrdered, NoMetadata}}}, Dict{String, Any}}

julia> typeof(g_ds[1])
YAXArray{Float64, 4, SubArray{Float64, 4, Array{Float64, 4}, Tuple{Vector{Int64}, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, false}, Tuple{Dim{:Ti, Sampled{
Date, SubArray{Date, 1, StepRange{Date, Day}, Tuple{Vector{Int64}}, false}, ForwardOrdered, Irregular{Tuple{Date, Date}}, Points, NoMetadata}}, X{Sampled{Float64, StepRangeLen{Float64, Base.TwicePrecision{Fl
oat64}, Base.TwicePrecision{Float64}, Int64}, ForwardOrdered, Regular{Float64}, Points, NoMetadata}}, Y{Sampled{Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int6
4}, ForwardOrdered, Regular{Float64}, Points, NoMetadata}}, Dim{:Variable, DimensionalData.Dimensions.Lookups.Categorical{String, SubArray{String, 1, Vector{String}, Tuple{Base.Slice{Base.OneTo{Int64}}}, tru
e}, ForwardOrdered, NoMetadata}}}, Dict{String, Any}}

@rafaqz
Copy link
Owner

rafaqz commented Apr 4, 2024

No turns out I just forgot to use format on the dimensions.

@rafaqz
Copy link
Owner

rafaqz commented Apr 4, 2024

Fixed on main

@rafaqz rafaqz closed this as completed Apr 4, 2024
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

2 participants