Skip to content

Commit

Permalink
Fix warnings (#502)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
tompollard authored Oct 8, 2024
2 parents 6a0de80 + 1ea701e commit 56b7d5c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
9 changes: 6 additions & 3 deletions tests/test_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_1(self):
# no null to detect in the output text file of rdann.

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

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

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

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

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

target_time = [None] * nannot
Expand Down
2 changes: 2 additions & 0 deletions wfdb/io/convert/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ def read_edf(
int(np.sum(v) % 65536) for v in np.transpose(sig_data)
] # not all values correct?

edf_file.close()

record = Record(
record_name=record_name_out,
n_sig=n_sig,
Expand Down
12 changes: 5 additions & 7 deletions wfdb/io/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _stream_dat(file_name, pn_dir, byte_count, start_byte, dtype):
content = f.read(byte_count)

# Convert to numpy array
sig_data = np.fromstring(content, dtype=dtype)
sig_data = np.frombuffer(content, dtype=dtype)

return sig_data

Expand Down Expand Up @@ -173,7 +173,7 @@ def _stream_annotation(file_name, pn_dir):
content = f.read()

# Convert to numpy array
ann_data = np.fromstring(content, dtype=np.dtype("<u1"))
ann_data = np.frombuffer(content, dtype=np.dtype("<u1"))

return ann_data

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

return
6 changes: 2 additions & 4 deletions wfdb/io/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -3117,8 +3117,6 @@ def dl_database(
print("Downloading files...")
# Create multiple processes to download files.
# Limit to 2 connections to avoid overloading the server
pool = multiprocessing.dummy.Pool(processes=2)
pool.map(download.dl_pn_file, dl_inputs)
with multiprocessing.dummy.Pool(processes=2) as pool:
pool.map(download.dl_pn_file, dl_inputs)
print("Finished downloading files")

return

0 comments on commit 56b7d5c

Please sign in to comment.