Skip to content

Commit 85a3747

Browse files
generic implementation for haskeys
1 parent 493df94 commit 85a3747

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/dataset.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ function Base.setindex!(ds::AbstractDataset,data::AbstractVariable,varname::Symb
169169
end
170170

171171

172+
function Base.haskey(ds::AbstractDataset,varname::SymbolOrString)
173+
return Symbol(varname) in Symbol.(keys(ds))
174+
end
175+
172176
"""
173177
varbyattrib(ds, attname = attval)
174178

test/memory_dataset.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ CDM.dimnames(v::MemoryVariable) = v.dimnames
101101
CDM.dataset(v::MemoryVariable) = v.parent_dataset
102102

103103
Base.keys(md::MemoryDataset) = keys(md.variables)
104-
Base.haskey(md::MemoryDataset,varname::SymbolOrString) = haskey(md.variables,String(varname))
105104
CDM.variable(md::MemoryDataset,varname::SymbolOrString) = md.variables[String(varname)]
106105
CDM.dimnames(md::MemoryDataset) = keys(md.dimensions)
107106
CDM.maskingvalue(md::MemoryDataset) = md.maskingvalue

test/test_multifile.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ using Test
33
import CommonDataModel as CDM
44
using DataStructures
55
using Dates
6-
import CommonDataModel: AbstractDataset, AbstractVariable, Attributes, Dimensions, CatArrays, defGroup, sync, chunking, deflate, checksum
6+
import CommonDataModel:
7+
@CF_str,
8+
AbstractDataset,
9+
AbstractVariable,
10+
Attributes,
11+
CatArrays,
12+
Dimensions,
13+
checksum,
14+
chunking,
15+
defGroup,
16+
deflate,
17+
fillvalue,
18+
sync
719

820
function example_file(TDS,i,array, fname = tempname();
921
varname = "var")
@@ -126,6 +138,8 @@ for deferopen in (false,true)
126138
local buf, ds_merged, fname_merged, var
127139

128140
mfds = TDS(fnames, deferopen = deferopen);
141+
142+
@test haskey(mfds,varname)
129143
var = variable(mfds,varname);
130144
data = var[:,:,:]
131145
@test C == var[:,:,:]

0 commit comments

Comments
 (0)