Skip to content

Commit 2541c70

Browse files
committed
cast filebytes to int64
NPY_PROMOTION_STATE=weak_and_warn reports that several variables changed from int64 to uint8. Casting to int64 addresses the issue.
1 parent 56b7d5c commit 2541c70

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

wfdb/io/annotation.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,7 @@ def proc_ann_bytes(filebytes, sampto):
21342134
"""
21352135
# Base annotation fields
21362136
sample, label_store, subtype, chan, num, aux_note = [], [], [], [], [], []
2137+
filebytes = filebytes.astype(np.int64)
21372138

21382139
# Indexing Variables
21392140

@@ -2216,16 +2217,17 @@ def proc_core_fields(filebytes, bpi):
22162217
22172218
"""
22182219
sample_diff = 0
2220+
filebytes = filebytes.astype(np.int64)
22192221

22202222
# The current byte pair will contain either the actual d_sample + annotation store value,
22212223
# or 0 + SKIP.
22222224
while filebytes[bpi, 1] >> 2 == 59:
22232225
# 4 bytes storing dt
22242226
skip_diff = (
2225-
(int(filebytes[bpi + 1, 0]) << 16)
2226-
+ (int(filebytes[bpi + 1, 1]) << 24)
2227-
+ (int(filebytes[bpi + 2, 0]) << 0)
2228-
+ (int(filebytes[bpi + 2, 1]) << 8)
2227+
(filebytes[bpi + 1, 0] << 16)
2228+
+ (filebytes[bpi + 1, 1] << 24)
2229+
+ (filebytes[bpi + 2, 0] << 0)
2230+
+ (filebytes[bpi + 2, 1] << 8)
22292231
)
22302232

22312233
# Data type is long integer (stored in two's complement). Range -2**31 to 2**31 - 1
@@ -2237,7 +2239,7 @@ def proc_core_fields(filebytes, bpi):
22372239

22382240
# Not a skip - it is the actual sample number + annotation type store value
22392241
label_store = filebytes[bpi, 1] >> 2
2240-
sample_diff += int(filebytes[bpi, 0] + 256 * (filebytes[bpi, 1] & 3))
2242+
sample_diff += np.int64(filebytes[bpi, 0]) + 256 * np.int64(filebytes[bpi, 1] & 3)
22412243
bpi = bpi + 1
22422244

22432245
return sample_diff, label_store, bpi

0 commit comments

Comments
 (0)