Skip to content

Commit

Permalink
Deprecate names -> keys as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jmert committed Dec 30, 2020
1 parent 325a3a1 commit 0157617
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/MAT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ read or write without creation or truncation.
Compression on reading is detected/handled automatically; the compress
keyword argument only affects write operations.
Use with `read`, `write`, `close`, `names`, and `haskey`.
Use with `read`, `write`, `close`, `keys`, and `haskey`.
"""
matopen

Expand Down Expand Up @@ -166,5 +166,9 @@ end
###

Base.@deprecate_binding exists haskey
@noinline function Base.names(matfile::Union{MAT_v5.Matlabv5File,MAT_HDF5.MatlabHDF5File})
Base.depwarn("`names(matfile)` is deprecated, use `keys(matfile)` instead.", :names)
return keys(matfile)
end

end
8 changes: 3 additions & 5 deletions src/MAT_HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ function read(f::MatlabHDF5File, name::String)
end

"""
names(matfile_handle) -> Vector{String}
keys(matfile_handle) -> Vector{String}
Return a list of variables in an opened Matlab file.
See `matopen`.
"""
names(f::MatlabHDF5File) = keys(f)
Base.keys(f::MatlabHDF5File) = filter!(x -> x!="#refs#" && x!="#subsystem#", keys(f.plain))

"""
haskey(matfile_handle, varname) -> Bool
Expand All @@ -281,11 +281,9 @@ Return true if a variable is present in an opened Matlab file.
See `matopen`.
"""

# HDF5v0.14+ H5DataStore uses keys/haskey
Base.keys(f::MatlabHDF5File) = filter!(x -> x!="#refs#" && x!="#subsystem#", keys(f.plain))
Base.haskey(p::MatlabHDF5File, path::String) = haskey(p.plain, path)


### Writing

# Check whether a varname is valid for MATLAB
Expand Down
3 changes: 1 addition & 2 deletions src/MAT_v5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

module MAT_v5
using CodecZlib, BufferedStreams, HDF5, SparseArrays
import Base: names, read, write, close
import Base: read, write, close

round_uint8(data) = round.(UInt8, data)
complex_array(a, b) = complex.(a, b)
Expand Down Expand Up @@ -398,7 +398,6 @@ function getvarnames(matfile::Matlabv5File)
matfile.varnames
end

names(matfile::Matlabv5File) = keys(matfile)
Base.haskey(matfile::Matlabv5File, varname::String) =
haskey(getvarnames(matfile), varname)
Base.keys(matfile::Matlabv5File) =
Expand Down
2 changes: 1 addition & 1 deletion test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function check(filename, result)
""")
end
end
@test union!(Set(), names(matfile)) == union!(Set(), keys(result))
@test union!(Set(), keys(matfile)) == union!(Set(), keys(result))
close(matfile)

mat = matread(filename)
Expand Down

0 comments on commit 0157617

Please sign in to comment.