From 80c052669f65cf2288a79725de1462528e776f11 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Thu, 16 Jan 2025 16:20:25 -0500 Subject: [PATCH 1/4] Set pytest to run in NPY_PROMOTION_STATE=weak_and_warn --- pyproject.toml | 1 + pytest.ini | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 pytest.ini diff --git a/pyproject.toml b/pyproject.toml index 09fbdad9..4df60e44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dynamic = ["version"] dev = [ "pytest >= 7.1.1", "pytest-xdist >= 2.5.0", + "pytest-env >= 1.1.5", "pylint >= 2.13.7", "black >= 22.3.0", "sphinx >= 4.5.0", diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..84a4055e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +env = + NPY_PROMOTION_STATE=weak_and_warn From bfb35cd7425d1b524fb179d4ca8c89ac26860ef7 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Thu, 16 Jan 2025 16:48:30 -0500 Subject: [PATCH 2/4] Change in type promotion. Fixes to edf.py --- wfdb/io/convert/edf.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wfdb/io/convert/edf.py b/wfdb/io/convert/edf.py index a2742015..1c91a06c 100644 --- a/wfdb/io/convert/edf.py +++ b/wfdb/io/convert/edf.py @@ -402,22 +402,24 @@ def read_edf( temp_sig_data = np.fromfile(edf_file, dtype=np.int16) temp_sig_data = temp_sig_data.reshape((-1, sum(samps_per_block))) temp_all_sigs = np.hsplit(temp_sig_data, np.cumsum(samps_per_block)[:-1]) + for i in range(n_sig): # Check if `samps_per_frame` has all equal values if samps_per_frame.count(samps_per_frame[0]) == len(samps_per_frame): sig_data[:, i] = ( - temp_all_sigs[i].flatten() - baseline[i] + temp_all_sigs[i].flatten().astype(np.int64) - baseline[i] ) / adc_gain_all[i] else: temp_sig_data = temp_all_sigs[i].flatten() + if samps_per_frame[i] == 1: - sig_data[:, i] = (temp_sig_data - baseline[i]) / adc_gain_all[i] + sig_data[:, i] = (temp_sig_data.astype(np.int64) - baseline[i]) / adc_gain_all[i] else: for j in range(sig_len): start_ind = j * samps_per_frame[i] stop_ind = start_ind + samps_per_frame[i] sig_data[j, i] = np.mean( - (temp_sig_data[start_ind:stop_ind] - baseline[i]) + temp_sig_data[start_ind:stop_ind].astype(np.int64) - baseline[i] / adc_gain_all[i] ) From 5e3cfca6bd3b999ddf3314ec880944fbfb5ec620 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Thu, 16 Jan 2025 17:15:35 -0500 Subject: [PATCH 3/4] Revert "Set pytest to run in NPY_PROMOTION_STATE=weak_and_warn" This reverts commit 80c052669f65cf2288a79725de1462528e776f11. weak_and_warn results in OverflowError in Numpy 1. --- pyproject.toml | 1 - pytest.ini | 3 --- 2 files changed, 4 deletions(-) delete mode 100644 pytest.ini diff --git a/pyproject.toml b/pyproject.toml index 4df60e44..09fbdad9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,6 @@ dynamic = ["version"] dev = [ "pytest >= 7.1.1", "pytest-xdist >= 2.5.0", - "pytest-env >= 1.1.5", "pylint >= 2.13.7", "black >= 22.3.0", "sphinx >= 4.5.0", diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 84a4055e..00000000 --- a/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -env = - NPY_PROMOTION_STATE=weak_and_warn From 262f49495839d1798d73a53cfc857bd5bb939765 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Thu, 16 Jan 2025 18:45:55 -0500 Subject: [PATCH 4/4] Fix formatting. --- wfdb/io/convert/edf.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wfdb/io/convert/edf.py b/wfdb/io/convert/edf.py index 1c91a06c..c2d0af47 100644 --- a/wfdb/io/convert/edf.py +++ b/wfdb/io/convert/edf.py @@ -413,14 +413,16 @@ def read_edf( temp_sig_data = temp_all_sigs[i].flatten() if samps_per_frame[i] == 1: - sig_data[:, i] = (temp_sig_data.astype(np.int64) - baseline[i]) / adc_gain_all[i] + sig_data[:, i] = ( + temp_sig_data.astype(np.int64) - baseline[i] + ) / adc_gain_all[i] else: for j in range(sig_len): start_ind = j * samps_per_frame[i] stop_ind = start_ind + samps_per_frame[i] sig_data[j, i] = np.mean( - temp_sig_data[start_ind:stop_ind].astype(np.int64) - baseline[i] - / adc_gain_all[i] + temp_sig_data[start_ind:stop_ind].astype(np.int64) + - baseline[i] / adc_gain_all[i] ) # This is the closest I can get to the original implementation