diff --git a/tests/test_annotation.py b/tests/test_annotation.py index e7d86b50..db3e71d0 100644 --- a/tests/test_annotation.py +++ b/tests/test_annotation.py @@ -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 @@ -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 @@ -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 diff --git a/wfdb/io/convert/edf.py b/wfdb/io/convert/edf.py index e77cda59..e3096884 100644 --- a/wfdb/io/convert/edf.py +++ b/wfdb/io/convert/edf.py @@ -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, diff --git a/wfdb/io/download.py b/wfdb/io/download.py index d494ad0e..338d8b97 100644 --- a/wfdb/io/download.py +++ b/wfdb/io/download.py @@ -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 @@ -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("