Skip to content

Commit 0efc6d8

Browse files
musmjmert
andauthored
Deprecate exists to haskey and names to keys and bump minor version in prep for HDF5 release (#156)
* Deprecate exists to haskey * Deprecate names -> keys as well * Maintain link through common binding while deprecating Co-authored-by: Justin Willmert <[email protected]>
1 parent 6398b8a commit 0efc6d8

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MAT"
22
uuid = "23992714-dd62-5051-b70f-ba57cb901cac"
3-
version = "0.9.2"
3+
version = "0.10.0"
44

55
[deps]
66
BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ To check for the presence of a variable name in a MAT file:
6868

6969
```julia
7070
file = matopen("matfile.mat")
71-
if exists(file, "variable")
71+
if haskey(file, "variable")
7272
# something
7373
end
7474
close(file)

src/MAT.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
module MAT
2626

2727
using HDF5, SparseArrays
28-
import HDF5: exists
2928

3029
include("MAT_HDF5.jl")
3130
include("MAT_v5.jl")
3231

3332
using .MAT_HDF5, .MAT_v5
3433

35-
export matopen, matread, matwrite, exists, @read, @write
34+
export matopen, matread, matwrite, @read, @write
3635

3736
# Open a MATLAB file
3837
const HDF5_HEADER = UInt8[0x89, 0x48, 0x44, 0x46, 0x0d, 0x0a, 0x1a, 0x0a]
@@ -116,7 +115,7 @@ read or write without creation or truncation.
116115
Compression on reading is detected/handled automatically; the compress
117116
keyword argument only affects write operations.
118117
119-
Use with `read`, `write`, `close`, `names`, and `exists`.
118+
Use with `read`, `write`, `close`, `keys`, and `haskey`.
120119
"""
121120
matopen
122121

@@ -161,5 +160,20 @@ function matwrite(filename::AbstractString, dict::AbstractDict{S, T}; compress::
161160
close(file)
162161
end
163162
end
163+
164+
###
165+
### v0.10.0 deprecations
166+
###
167+
168+
import HDF5: exists
169+
export exists
170+
@noinline function exists(matfile::Union{MAT_v5.Matlabv5File,MAT_HDF5.MatlabHDF5File}, varname::String)
171+
Base.depwarn("`exists(matfile, varname)` is deprecated, use `haskey(matfile, varname)` instead.", :exists)
172+
return haskey(matfile, varname)
173+
end
174+
@noinline function Base.names(matfile::Union{MAT_v5.Matlabv5File,MAT_HDF5.MatlabHDF5File})
175+
Base.depwarn("`names(matfile)` is deprecated, use `keys(matfile)` instead.", :names)
176+
return keys(matfile)
164177
end
165178

179+
end

src/MAT_HDF5.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
module MAT_HDF5
3030

3131
using HDF5, SparseArrays
32-
# deprecated for HDF5 v0.14+, but use deprecated binding to have common function with
33-
# e.g. JLD.jl
34-
import HDF5: exists
3532

3633
import Base: names, read, write, close
3734
import HDF5: Reference
@@ -269,25 +266,21 @@ function read(f::MatlabHDF5File, name::String)
269266
end
270267

271268
"""
272-
names(matfile_handle) -> Vector{String}
269+
keys(matfile_handle) -> Vector{String}
273270
274271
Return a list of variables in an opened Matlab file.
275272
276273
See `matopen`.
277274
"""
278-
names(f::MatlabHDF5File) = keys(f)
275+
Base.keys(f::MatlabHDF5File) = filter!(x -> x!="#refs#" && x!="#subsystem#", keys(f.plain))
279276

280277
"""
281-
exists(matfile_handle, varname) -> Bool
278+
haskey(matfile_handle, varname) -> Bool
282279
283280
Return true if a variable is present in an opened Matlab file.
284281
285282
See `matopen`.
286283
"""
287-
exists(p::MatlabHDF5File, path::String) = haskey(p, path)
288-
289-
# HDF5v0.14+ H5DataStore uses keys/haskey
290-
Base.keys(f::MatlabHDF5File) = filter!(x -> x!="#refs#" && x!="#subsystem#", keys(f.plain))
291284
Base.haskey(p::MatlabHDF5File, path::String) = haskey(p.plain, path)
292285

293286
### Writing

src/MAT_v5.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727

2828
module MAT_v5
2929
using CodecZlib, BufferedStreams, HDF5, SparseArrays
30-
import Base: names, read, write, close
31-
# deprecated for HDF5 v0.14+, but use deprecated binding to have common function with
32-
# e.g. JLD.jl
33-
import HDF5: exists
30+
import Base: read, write, close
3431

3532
round_uint8(data) = round.(UInt8, data)
3633
complex_array(a, b) = complex.(a, b)
@@ -401,9 +398,6 @@ function getvarnames(matfile::Matlabv5File)
401398
matfile.varnames
402399
end
403400

404-
exists(matfile::Matlabv5File, varname::String) = haskey(matfile, varname)
405-
names(matfile::Matlabv5File) = keys(matfile)
406-
# HDF5v0.14+ DataFile uses keys/haskey
407401
Base.haskey(matfile::Matlabv5File, varname::String) =
408402
haskey(getvarnames(matfile), varname)
409403
Base.keys(matfile::Matlabv5File) =

test/read.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using MAT, Test
33
function check(filename, result)
44
matfile = matopen(filename)
55
for (k, v) in result
6-
@test exists(matfile, k)
6+
@test haskey(matfile, k)
77
got = read(matfile, k)
88
if !isequal(got, v) || (typeof(got) != typeof(v) && (!isa(got, String) || !(isa(v, String))))
99
close(matfile)
@@ -20,7 +20,7 @@ function check(filename, result)
2020
""")
2121
end
2222
end
23-
@test union!(Set(), names(matfile)) == union!(Set(), keys(result))
23+
@test union!(Set(), keys(matfile)) == union!(Set(), keys(result))
2424
close(matfile)
2525

2626
mat = matread(filename)

0 commit comments

Comments
 (0)