You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a regular vector, v[idx] "works" even if idx == Int64[]. This is a useful property to gracefully handle edge cases. For a netCDF variable, however, v[ [] ] fails with
ERROR: LoadError: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
It would be nice if an empty array is supported. The following is a self-contained example where it would be useful.
using Dates
using NCDatasets
using Plots
t0 =DateTime(2015,5,27)
t1 =DateTime(2015,5,28)
t2 =DateTime(2015,5,29)
t3 =DateTime(2015,5,30)
functionmakeplots(tax, v)
ls =findall(t -> (t1 <= t <= t2), tax)
@show ls
plot(tax[ls], v[ls]; xlim=(t1,t3))
sleep(3)
ls =findall(t -> (t2 <= t <= t3), tax)
@show ls
display(plot!(tax[ls], v[ls]))
end
tax =DateTime(2015,5,28):Dates.Hour(1):DateTime(2015,5,28,23)
myvar =rand(Float64, length(tax)) # fake values# worksmakeplots(tax,myvar) # works# create a sampleNCDataset("tmp.nc", "c") do ds
defVar(ds, "time", tax, ("time",))
defVar(ds, "myvar", myvar, ("time",))
end# failsNCDataset("tmp.nc", "r") do ds
makeplots(ds["time"], ds["myvar"])
end
The text was updated successfully, but these errors were encountered:
I didn't know that was an "error"! I meant to suggest that it would be nice if the empty-array behavior is emulated as an enhancement in the future because it's sometimes useful. (If I thought it was an error, I would have shortened my example, just to reproduce the error. I wanted to explain in what kind of situations the empty-array behavior may be useful.)
In fact, the old behavior was inconsistent (and empty range 1:0 would have worked, but not Int[]). The error message was just triggered in the checking assert code.
For a regular vector,
v[idx]
"works" even ifidx == Int64[]
. This is a useful property to gracefully handle edge cases. For a netCDF variable, however,v[ [] ]
fails withIt would be nice if an empty array is supported. The following is a self-contained example where it would be useful.
The text was updated successfully, but these errors were encountered: