Skip to content

Commit 56b7d5c

Browse files
authored
Fix warnings (#502)
I've fixed a few warnings related to - deprecated functions - unclosed files - unclosed multiprocessing pool Now all tests pass without warnings (and errors of course).
2 parents 6a0de80 + 1ea701e commit 56b7d5c

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

tests/test_annotation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def test_1(self):
3333
# no null to detect in the output text file of rdann.
3434

3535
# Target data from WFDB software package
36-
lines = tuple(open("tests/target-output/ann-1", "r"))
36+
with open("tests/target-output/ann-1", "r") as f:
37+
lines = tuple(f)
3738
nannot = len(lines)
3839

3940
target_time = [None] * nannot
@@ -108,7 +109,8 @@ def test_2(self):
108109
annotation = wfdb.rdann("sample-data/12726", "anI")
109110

110111
# Target data from WFDB software package
111-
lines = tuple(open("tests/target-output/ann-2", "r"))
112+
with open("tests/target-output/ann-2", "r") as f:
113+
lines = tuple(f)
112114
nannot = len(lines)
113115

114116
target_time = [None] * nannot
@@ -181,7 +183,8 @@ def test_3(self):
181183
annotation = wfdb.rdann("sample-data/1003", "atr")
182184

183185
# Target data from WFDB software package
184-
lines = tuple(open("tests/target-output/ann-3", "r"))
186+
with open("tests/target-output/ann-3", "r") as f:
187+
lines = tuple(f)
185188
nannot = len(lines)
186189

187190
target_time = [None] * nannot

wfdb/io/convert/edf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ def read_edf(
438438
int(np.sum(v) % 65536) for v in np.transpose(sig_data)
439439
] # not all values correct?
440440

441+
edf_file.close()
442+
441443
record = Record(
442444
record_name=record_name_out,
443445
n_sig=n_sig,

wfdb/io/download.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _stream_dat(file_name, pn_dir, byte_count, start_byte, dtype):
143143
content = f.read(byte_count)
144144

145145
# Convert to numpy array
146-
sig_data = np.fromstring(content, dtype=dtype)
146+
sig_data = np.frombuffer(content, dtype=dtype)
147147

148148
return sig_data
149149

@@ -173,7 +173,7 @@ def _stream_annotation(file_name, pn_dir):
173173
content = f.read()
174174

175175
# Convert to numpy array
176-
ann_data = np.fromstring(content, dtype=np.dtype("<u1"))
176+
ann_data = np.frombuffer(content, dtype=np.dtype("<u1"))
177177

178178
return ann_data
179179

@@ -343,7 +343,7 @@ def get_annotators(db_dir, annotators):
343343
annotators = ann_list
344344
else:
345345
# In case they didn't input a list
346-
if type(annotators) == str:
346+
if type(annotators) is str:
347347
annotators = [annotators]
348348
# user input ones. Check validity.
349349
for a in annotators:
@@ -541,8 +541,6 @@ def dl_files(db, dl_dir, files, keep_subdirs=True, overwrite=False):
541541
print("Downloading files...")
542542
# Create multiple processes to download files.
543543
# Limit to 2 connections to avoid overloading the server
544-
pool = multiprocessing.dummy.Pool(processes=2)
545-
pool.map(dl_pn_file, dl_inputs)
544+
with multiprocessing.dummy.Pool(processes=2) as pool:
545+
pool.map(dl_pn_file, dl_inputs)
546546
print("Finished downloading files")
547-
548-
return

wfdb/io/record.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,8 +3117,6 @@ def dl_database(
31173117
print("Downloading files...")
31183118
# Create multiple processes to download files.
31193119
# Limit to 2 connections to avoid overloading the server
3120-
pool = multiprocessing.dummy.Pool(processes=2)
3121-
pool.map(download.dl_pn_file, dl_inputs)
3120+
with multiprocessing.dummy.Pool(processes=2) as pool:
3121+
pool.map(download.dl_pn_file, dl_inputs)
31223122
print("Finished downloading files")
3123-
3124-
return

0 commit comments

Comments
 (0)