Skip to content

Commit 17b3f74

Browse files
centralize the definition of allowed indices (to reduce ambiguities)
1 parent d8febca commit 17b3f74

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

src/cfconventions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ allowmissing(x::AbstractArray{T}) where {T} = convert(AbstractArray{Union{T, Mis
4444

4545

4646

47-
function _filter(ncv::AbstractVariable, indices::Union{<:Integer,AbstractVector{<:Integer},Colon}...; accepted_status_flags = nothing)
47+
function _filter(ncv::AbstractVariable, indices...; accepted_status_flags = nothing)
4848
data = allowmissing(ncv[indices...])
4949

5050
if (accepted_status_flags != nothing)

src/cfvariable.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,21 +442,21 @@ end
442442
#@inline CFinvtransformdata(data::Char,fv,scale_factor,add_offset,time_origin,time_factor,DT) = CFtransform_replace_missing(data,fv)
443443

444444

445-
function Base.getindex(v::CFVariable, indexes::Union{Integer,Colon,AbstractRange{<:Integer},AbstractVector{<:Integer}}...)
445+
function Base.getindex(v::CFVariable, indexes::TIndices...)
446446
data = v.var[indexes...]
447447
return CFtransformdata(data,fill_and_missing_values(v),scale_factor(v),add_offset(v),
448448
time_origin(v),time_factor(v),maskingvalue(v),eltype(v))
449449
end
450450

451-
function Base.setindex!(v::CFVariable,data::Array{Missing,N},indexes::Union{Int,Colon,AbstractRange{<:Integer}}...) where N
451+
function Base.setindex!(v::CFVariable,data::Array{Missing,N},indexes::TIndices...) where N
452452
v.var[indexes...] = fill(fillvalue(v),size(data))
453453
end
454454

455-
function Base.setindex!(v::CFVariable,data::Missing,indexes::Union{Int,Colon,AbstractRange{<:Integer}}...)
455+
function Base.setindex!(v::CFVariable,data::Missing,indexes::TIndices...)
456456
v.var[indexes...] = fillvalue(v)
457457
end
458458

459-
function Base.setindex!(v::CFVariable,data::Union{T,Array{T,N}},indexes::Union{Int,Colon,AbstractRange{<:Integer}}...) where N where T <: Union{AbstractCFDateTime,DateTime,Union{Missing,DateTime,AbstractCFDateTime}}
459+
function Base.setindex!(v::CFVariable,data::Union{T,Array{T,N}},indexes::TIndices...) where N where T <: Union{AbstractCFDateTime,DateTime,Union{Missing,DateTime,AbstractCFDateTime}}
460460

461461
if calendar(v) !== nothing
462462
# can throw an convertion error if calendar attribute already exists and
@@ -473,7 +473,7 @@ function Base.setindex!(v::CFVariable,data::Union{T,Array{T,N}},indexes::Union{I
473473
end
474474

475475

476-
function Base.setindex!(v::CFVariable,data,indexes::Union{Int,Colon,AbstractRange{<:Integer}}...)
476+
function Base.setindex!(v::CFVariable,data,indexes::TIndices...)
477477
v.var[indexes...] = CFinvtransformdata(
478478
data,fill_and_missing_values(v),
479479
scale_factor(v),add_offset(v),
@@ -602,7 +602,7 @@ NCDatasets.load!(ncv,data,buffer,:,:,:)
602602
close(ds)
603603
```
604604
"""
605-
@inline function load!(v::Union{CFVariable{T,N},MFCFVariable{T,N},SubVariable{T,N}}, data, buffer, indices::Union{Integer, AbstractRange{<:Integer}, Colon}...) where {T,N}
605+
@inline function load!(v::Union{CFVariable{T,N},MFCFVariable{T,N},SubVariable{T,N}}, data, buffer, indices::TIndices...) where {T,N}
606606

607607
if v.var == nothing
608608
return load!(v,indices...)

src/groupby.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,36 +518,36 @@ function Base.Array(gr::ReducedGroupedVariable)
518518
gr[ntuple(i -> Colon(),ndims(gr))...]
519519
end
520520

521-
function Base.getindex(gr::ReducedGroupedVariable{T,N,TGV,typeof(sum)},indices::Union{Integer,Colon,AbstractRange{<:Integer},AbstractVector{<:Integer}}...) where {T,N,TGV}
521+
function Base.getindex(gr::ReducedGroupedVariable{T,N,TGV,typeof(sum)},indices::TIndices...) where {T,N,TGV}
522522
data,count = _mapreduce(gr.gv.map_fun,+,gr.gv,indices)
523523
data
524524
end
525525

526-
function Base.getindex(gr::ReducedGroupedVariable{T,N,TGV,typeof(mean)},indices::Union{Integer,Colon,AbstractRange{<:Integer},AbstractVector{<:Integer}}...) where {T,N,TGV}
526+
function Base.getindex(gr::ReducedGroupedVariable{T,N,TGV,typeof(mean)},indices::TIndices...) where {T,N,TGV}
527527
data,count = _mapreduce(gr.gv.map_fun,+,gr.gv,indices)
528528
data ./ count
529529
end
530530

531531

532-
function Base.getindex(gr::ReducedGroupedVariable{T,N,TGV,TF},indices::Union{Integer,Colon,AbstractRange{<:Integer},AbstractVector{<:Integer}}...) where TF <: Union{typeof(var),typeof(maximum),typeof(minimum)} where {T,N,TGV}
532+
function Base.getindex(gr::ReducedGroupedVariable{T,N,TGV,TF},indices::TIndices...) where TF <: Union{typeof(var),typeof(maximum),typeof(minimum)} where {T,N,TGV}
533533

534534
return _mapreduce_aggregation(
535535
gr.gv.map_fun,aggregator(TF),gr.gv,indices);
536536
end
537537

538538

539-
function Base.getindex(gr::ReducedGroupedVariable{T,N,TGV,typeof(std)},indices::Union{Integer,Colon,AbstractRange{<:Integer},AbstractVector{<:Integer}}...) where {T,N,TGV}
539+
function Base.getindex(gr::ReducedGroupedVariable{T,N,TGV,typeof(std)},indices::TIndices...) where {T,N,TGV}
540540

541541
return sqrt.(_mapreduce_aggregation(
542542
gr.gv.map_fun,VarianceWelfordAggregation,gr.gv,indices))
543543
end
544544

545545

546-
_dim_after_getindex(dim,ind::Union{Colon,AbstractRange,AbstractVector},other...) = _dim_after_getindex(dim+1,other...)
546+
_dim_after_getindex(dim,ind::TIndices,other...) = _dim_after_getindex(dim+1,other...)
547547
_dim_after_getindex(dim,ind::Integer,other...) = _dim_after_getindex(dim,other...)
548548
_dim_after_getindex(dim) = dim
549549

550-
function Base.getindex(gr::ReducedGroupedVariable{T},indices::Union{Integer,Colon,AbstractRange{<:Integer},AbstractVector{<:Integer}}...) where T
550+
function Base.getindex(gr::ReducedGroupedVariable{T},indices::TIndices...) where T
551551
gv = gr.gv
552552
sz = size_getindex(gr,indices...)
553553
data_by_class = Array{T}(undef,sz)

src/multifile.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ function Base.keys(mfds::MFDataset)
157157
end
158158
end
159159

160-
Base.getindex(v::MFVariable,indexes::Union{Integer,Colon,AbstractRange{<:Integer}}...) = getindex(v.var,indexes...)
161-
Base.setindex!(v::MFVariable,data,indexes::Union{Integer,Colon,AbstractRange{<:Integer}}...) = setindex!(v.var,data,indexes...)
160+
Base.getindex(v::MFVariable,indexes::TIndices...) = getindex(v.var,indexes...)
161+
Base.setindex!(v::MFVariable,data,indexes::TIndices...) = setindex!(v.var,data,indexes...)
162162

163163

164164
load!(v::MFVariable,buffer,indexes...) = CatArrays.load!(v.var,buffer,indexes...)

src/subvariable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565

6666
Base.Array(v::SubVariable) = collect(v)
6767

68-
function Base.view(v::SubVariable,indices::Union{Int,Colon,AbstractVector{Int}}...)
68+
function Base.view(v::SubVariable,indices::Union{<:Integer,Colon,AbstractVector{<:Integer}}...)
6969
sub_indices = subsub(v.indices,indices)
7070
SubVariable(parent(v),sub_indices...)
7171
end
@@ -96,7 +96,7 @@ close(ds)
9696
```
9797
9898
"""
99-
Base.view(v::AbstractVariable,indices::Union{Int,Colon,AbstractVector{Int}}...) = SubVariable(v,indices...)
99+
Base.view(v::AbstractVariable,indices::Union{<:Integer,Colon,AbstractVector{<:Integer}}...) = SubVariable(v,indices...)
100100
Base.view(v::SubVariable,indices::CartesianIndex) = view(v,indices.I...)
101101
Base.view(v::SubVariable,indices::CartesianIndices) = view(v,indices.indices...)
102102

0 commit comments

Comments
 (0)