From 0636c75f2af52c9c373d6ed38c33650f55f58c6c Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Wed, 9 Oct 2024 17:22:49 -0400 Subject: [PATCH 1/3] cast filebytes to int/int64 NPY_PROMOTION_STATE=weak_and_warn reports that several variables changed from int64 to uint8. --- wfdb/io/annotation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wfdb/io/annotation.py b/wfdb/io/annotation.py index b398fa07..8182b0cf 100644 --- a/wfdb/io/annotation.py +++ b/wfdb/io/annotation.py @@ -2219,7 +2219,7 @@ def proc_core_fields(filebytes, bpi): # The current byte pair will contain either the actual d_sample + annotation store value, # or 0 + SKIP. - while filebytes[bpi, 1] >> 2 == 59: + while int(filebytes[bpi, 1]) >> 2 == 59: # 4 bytes storing dt skip_diff = ( (int(filebytes[bpi + 1, 0]) << 16) @@ -2237,7 +2237,9 @@ def proc_core_fields(filebytes, bpi): # Not a skip - it is the actual sample number + annotation type store value label_store = filebytes[bpi, 1] >> 2 - sample_diff += int(filebytes[bpi, 0] + 256 * (filebytes[bpi, 1] & 3)) + sample_diff += np.int64(filebytes[bpi, 0]) + 256 * np.int64( + filebytes[bpi, 1] & 3 + ) bpi = bpi + 1 return sample_diff, label_store, bpi From 0ab9d5cc83aabf73c13083229437930c4104d8bc Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Thu, 10 Oct 2024 16:39:09 -0400 Subject: [PATCH 2/3] case filebytes[bpi, 1] >> 2 to int resolve UserWarning: result dtype changed due to the removal of value-based promotion from NumPy. Changed from int64 to uint8. --- wfdb/io/annotation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wfdb/io/annotation.py b/wfdb/io/annotation.py index 8182b0cf..611268bf 100644 --- a/wfdb/io/annotation.py +++ b/wfdb/io/annotation.py @@ -2162,7 +2162,7 @@ def proc_ann_bytes(filebytes, sampto): update = {"subtype": True, "chan": True, "num": True, "aux_note": True} # Get the next label store value - it may indicate additional # fields for this annotation, or the values of the next annotation. - current_label_store = filebytes[bpi, 1] >> 2 + current_label_store = int(filebytes[bpi, 1]) >> 2 while current_label_store > 59: subtype, chan, num, aux_note, update, bpi = proc_extra_field( @@ -2176,7 +2176,7 @@ def proc_ann_bytes(filebytes, sampto): update, ) - current_label_store = filebytes[bpi, 1] >> 2 + current_label_store = int(filebytes[bpi, 1]) >> 2 # Set defaults or carry over previous values if necessary subtype, chan, num, aux_note = update_extra_fields( @@ -2236,7 +2236,7 @@ def proc_core_fields(filebytes, bpi): bpi = bpi + 3 # Not a skip - it is the actual sample number + annotation type store value - label_store = filebytes[bpi, 1] >> 2 + label_store = int(filebytes[bpi, 1]) >> 2 sample_diff += np.int64(filebytes[bpi, 0]) + 256 * np.int64( filebytes[bpi, 1] & 3 ) From 6e99aa1dead27971011dd01046586bc93eff693e Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Fri, 11 Oct 2024 15:54:41 -0400 Subject: [PATCH 3/3] cast type fix 'UserWarning: result dtype changed due to the removal of value-based promotion from NumPy'. --- wfdb/io/annotation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wfdb/io/annotation.py b/wfdb/io/annotation.py index 611268bf..6ceb2680 100644 --- a/wfdb/io/annotation.py +++ b/wfdb/io/annotation.py @@ -2237,8 +2237,8 @@ def proc_core_fields(filebytes, bpi): # Not a skip - it is the actual sample number + annotation type store value label_store = int(filebytes[bpi, 1]) >> 2 - sample_diff += np.int64(filebytes[bpi, 0]) + 256 * np.int64( - filebytes[bpi, 1] & 3 + sample_diff += np.int64(filebytes[bpi, 0]) + 256 * ( + np.int64(filebytes[bpi, 1]) & 3 ) bpi = bpi + 1 @@ -2324,7 +2324,7 @@ def proc_extra_field( aux_notebytes = filebytes[ bpi + 1 : bpi + 1 + int(np.ceil(aux_notelen / 2.0)), : ].flatten() - if aux_notelen & 1: + if int(aux_notelen) & 1: aux_notebytes = aux_notebytes[:-1] # The aux_note string aux_note.append("".join([chr(char) for char in aux_notebytes]))