Skip to content

Commit

Permalink
Symbols for indexing a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Oct 19, 2023
1 parent 825ad5b commit 0928e47
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cfvariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ function Base.keys(v::AbstractVariable)
end


function Base.getindex(v::AbstractVariable,name::AbstractString)
function Base.getindex(v::AbstractVariable,name::SymbolOrString)
ds = dataset(v)
ncvar = ds[name]
if _isrelated(ncvar,v)
Expand Down
6 changes: 6 additions & 0 deletions test/test_cfconventions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,11 @@ ds = NCDataset(fname)
@test_throws KeyError ds[CF"longitude"] # error

nclon_u2 = ds["ubar"][CF"longitude"]
@test name(nclon_u2) == "lon_u"


nclon_u2 = ds["ubar"]["lon_u"]
@test name(nclon_u2) == "lon_u"

nclon_u2 = ds["ubar"][:lon_u]
@test name(nclon_u2) == "lon_u"

0 comments on commit 0928e47

Please sign in to comment.