YAXArrays.jl icon indicating copy to clipboard operation
YAXArrays.jl copied to clipboard

Allow Dataset indexing using Sets

Open Qfl3x opened this issue 2 years ago • 2 comments
trafficstars

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 avatar Aug 24 '23 07:08 Qfl3x

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.

Qfl3x avatar Aug 24 '23 07:08 Qfl3x

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

rafaqz avatar Aug 24 '23 08:08 rafaqz