Skip to content

Commit f01ad31

Browse files
authored
Rename names to keys to better align with dict-like interface (#698)
1 parent 0783ac9 commit f01ad31

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

src/HDF5.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Requires: @require
55

66
import Base:
77
close, convert, eltype, lastindex, flush, getindex, ==,
8-
isempty, isvalid, length, names, ndims, parent, read,
8+
isempty, isvalid, length, ndims, parent, read,
99
setindex!, show, size, sizeof, write, isopen, iterate, eachindex, axes
1010

1111
import Libdl
@@ -537,7 +537,7 @@ function h5readattr(filename, name::String)
537537
fid = h5open(filename,"r")
538538
try
539539
a = attrs(fid[name])
540-
dat = Dict(x => read(a[x]) for x in names(a))
540+
dat = Dict(x => read(a[x]) for x in keys(a))
541541
finally
542542
close(fid)
543543
end
@@ -959,13 +959,13 @@ end
959959
filename(obj::Union{File,Group,Dataset,Attribute,Datatype}) = h5f_get_name(checkvalid(obj).id)
960960
name(obj::Union{File,Group,Dataset,Datatype}) = h5i_get_name(checkvalid(obj).id)
961961
name(attr::Attribute) = h5a_get_name(attr.id)
962-
function names(x::Union{Group,File})
962+
function Base.keys(x::Union{Group,File})
963963
checkvalid(x)
964964
n = length(x)
965965
return [h5l_get_name_by_idx(x, ".", H5_INDEX_NAME, H5_ITER_INC, i-1, H5P_DEFAULT) for i = 1:n]
966966
end
967967

968-
function names(x::Attributes)
968+
function Base.keys(x::Attributes)
969969
checkvalid(x.parent)
970970
n = length(x)
971971
return [h5a_get_name_by_idx(x.parent, ".", H5_INDEX_NAME, H5_ITER_INC, i-1, H5P_DEFAULT) for i = 1:n]
@@ -1866,7 +1866,7 @@ end
18661866
if isa(node, Dataset)
18671867
push!(list, node)
18681868
else
1869-
for c in names(node)
1869+
for c in keys(node)
18701870
get_datasets!(list, node[c])
18711871
end
18721872
end

src/datafile.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ read(f::Base.Callable, parent::DataFile, name::String...) =
3939

4040
# Read every variable in the file
4141
function read(f::DataFile)
42-
vars = names(f)
42+
vars = keys(f)
4343
vals = Vector{Any}(undef,length(vars))
4444
for i = 1:length(vars)
4545
vals[i] = read(f, vars[i])

src/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,6 @@ end
217217
@deprecate_binding ScalarOrString Union{ScalarType,String} false
218218
@deprecate_binding HDF5Scalar ScalarType false
219219
@deprecate_binding HDF5BitsKind BitsType false
220+
221+
### Changed in PR#695
222+
@deprecate names(x::Union{Group,File,Attributes}) keys(x)

test/mpio.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ end
3737
MPI.Barrier(comm)
3838
h5open(fn, comm) do f # default: opened in read mode, with default MPI.Info()
3939
@test isopen(f)
40-
@test names(f) == ["mygroup"]
40+
@test keys(f) == ["mygroup"]
4141

4242
B = read(f, "mygroup/B", dxpl_mpio=HDF5.H5FD_MPIO_COLLECTIVE)
4343
@test !isempty(B)

test/plain.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ h5open(fn, "w") do fid
272272
end
273273
end
274274
fid = h5open(fn, "r")
275-
@test names(fid) == ["mygroup"]
275+
@test keys(fid) == ["mygroup"]
276276
g = fid["mygroup"]
277-
@test names(g) == ["x"]
277+
@test keys(g) == ["x"]
278278
close(g)
279279
close(fid)
280280
rm(fn)
@@ -291,8 +291,8 @@ h5rewrite(outfile) do fid
291291
end
292292
@test length(readdir(tmpdir)) == 1
293293
h5open(outfile, "r") do fid
294-
@test names(fid) == ["mygroup"]
295-
@test names(fid["mygroup"]) == ["x"]
294+
@test keys(fid) == ["mygroup"]
295+
@test keys(fid["mygroup"]) == ["x"]
296296
end
297297

298298
# fail to overwrite
@@ -304,8 +304,8 @@ end
304304
end
305305
@test length(readdir(tmpdir)) == 1
306306
h5open(outfile, "r") do fid
307-
@test names(fid) == ["mygroup"]
308-
@test names(fid["mygroup"]) == ["x"]
307+
@test keys(fid) == ["mygroup"]
308+
@test keys(fid["mygroup"]) == ["x"]
309309
end
310310

311311
# overwrite
@@ -316,8 +316,8 @@ h5rewrite(outfile) do fid
316316
end
317317
@test length(readdir(tmpdir)) == 1
318318
h5open(outfile, "r") do fid
319-
@test names(fid) == ["mygroup"]
320-
@test names(fid["mygroup"]) == ["y"]
319+
@test keys(fid) == ["mygroup"]
320+
@test keys(fid["mygroup"]) == ["y"]
321321
end
322322
rm(tmpdir, recursive=true)
323323

0 commit comments

Comments
 (0)