Skip to content

Commit e1fffef

Browse files
authored
Merge pull request #11 from JuliaGeo/rs/parent
add `Base.parent` method for variable, and use it
2 parents 70c9f5c + 287648a commit e1fffef

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/variable.jl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11

2-
Base.getindex(v::ZarrVariable,ij::Union{Integer,Colon,AbstractVector{<:Integer}}...) = v.zarray[ij...]
3-
CDM.load!(v::ZarrVariable,buffer,ij...) = buffer .= view(v.zarray,ij...)
4-
2+
Base.getindex(v::ZarrVariable,ij::Union{Integer,Colon,AbstractVector{<:Integer}}...) = parent(v)[ij...]
53
function Base.setindex!(v::ZarrVariable,data,ij::Union{Integer,Colon,AbstractVector{<:Integer}}...)
6-
v.zarray[ij...] = data
4+
parent(v)[ij...] = data
75
end
8-
Base.size(v::ZarrVariable) = size(v.zarray)
9-
CDM.name(v::ZarrVariable) = Zarr.zname(v.zarray)
10-
CDM.dimnames(v::ZarrVariable) = Tuple(reverse(v.zarray.attrs["_ARRAY_DIMENSIONS"]))
6+
Base.size(v::ZarrVariable) = size(parent(v))
7+
Base.parent(v::ZarrVariable) = v.zarray
8+
9+
10+
CDM.load!(v::ZarrVariable,buffer,ij...) = buffer .= view(parent(v),ij...)
11+
CDM.name(v::ZarrVariable) = Zarr.zname(parent(v))
12+
CDM.dimnames(v::ZarrVariable) = Tuple(reverse(parent(v).attrs["_ARRAY_DIMENSIONS"]))
1113
CDM.dataset(v::ZarrVariable) = v.parentdataset
1214

1315
function _iscoordvar(v)
@@ -19,36 +21,36 @@ function _iscoordvar(v)
1921
end
2022

2123
function CDM.attribnames(v::ZarrVariable)
22-
names = filter(!=("_ARRAY_DIMENSIONS"),keys(v.zarray.attrs))
23-
if !isnothing(v.zarray.metadata.fill_value) && !_iscoordvar(v)
24+
names = filter(!=("_ARRAY_DIMENSIONS"),keys(parent(v).attrs))
25+
if !isnothing(parent(v).metadata.fill_value) && !_iscoordvar(v)
2426
push!(names,"_FillValue")
2527
end
2628
return names
2729
end
2830

2931
function CDM.attrib(v::ZarrVariable{T},name::SymbolOrString) where T
30-
if String(name) == "_FillValue" && !isnothing(v.zarray.metadata.fill_value)
31-
return T(v.zarray.metadata.fill_value)
32+
if String(name) == "_FillValue" && !isnothing(parent(v).metadata.fill_value)
33+
return T(parent(v).metadata.fill_value)
3234
end
33-
return v.zarray.attrs[String(name)]
35+
return parent(v).attrs[String(name)]
3436
end
3537

3638
function CDM.defAttrib(v::ZarrVariable,name::SymbolOrString,value)
3739
@assert iswritable(dataset(v))
3840
@assert String(name) !== "_FillValue"
3941

40-
v.zarray.attrs[String(name)] = value
42+
parent(v).attrs[String(name)] = value
4143

42-
storage = v.zarray.storage
44+
storage = parent(v).storage
4345
io = IOBuffer()
44-
JSON.print(io, v.zarray.attrs)
45-
storage[v.zarray.path,".zattrs"] = take!(io)
46+
JSON.print(io, parent(v).attrs)
47+
storage[parent(v).path,".zattrs"] = take!(io)
4648
end
4749

4850

4951
# DiskArray methods
50-
eachchunk(v::ZarrVariable) = eachchunk(v.zarray)
51-
haschunks(v::ZarrVariable) = haschunks(v.zarray)
52+
eachchunk(v::ZarrVariable) = eachchunk(parent(v))
53+
haschunks(v::ZarrVariable) = haschunks(parent(v))
5254
eachchunk(v::CFVariable{T,N,<:ZarrVariable}) where {T,N} = eachchunk(v.var)
5355
haschunks(v::CFVariable{T,N,<:ZarrVariable}) where {T,N} = haschunks(v.var)
5456

0 commit comments

Comments
 (0)