JuliaDataCubes / YAXArrays.jl

Yet Another XArray-like Julia package
https://juliadatacubes.github.io/YAXArrays.jl/
Other
101 stars 18 forks source link

Allow Dataset indexing using Sets #322

Closed Qfl3x closed 2 weeks ago

Qfl3x commented 1 year ago

Currently, indexing by Sets isn't supported:

using EarthDataLab
ds = esdd()
a = [:cot, :ctt] 
ds[a] # Works fine
s = Set(a)
ds[s]  #No method matching getindex(DataSet, Set)
# Workaround
ds[collect(s)] # Turns s into an array

This may make issues like #321 simpler by using setdiff; example:

using EarthDataLab
ds = esdd()
bad_vars = [:cot, :ctt] # Variables we don't want
ds[setdiff(keys(ds.cubes), bad_vars)]
Qfl3x commented 1 year ago

Also noticed that dataset indexing does not accept duplicates:

a = [:cot, :cot]
ds[a] # Gives a Dataset with only one variable

Meaning that the getindex(Dataset, Set) implementation could be "simpler" than just an override with collect.

rafaqz commented 1 year ago

Sets are not ordered, so indexing with them will be in a random order. Usually we dont want that.