Skip to content

Commit e09eeb9

Browse files
committed
allow length 1 annotations
1 parent fb7fabb commit e09eeb9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

wfdb/readwrite/annotations.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,12 @@ def checkfield(self, field):
276276
raise ValueError('Subelements of the '+field+' field must not contain tabs or newlines')
277277

278278
elif field == 'sample':
279-
sampdiffs = np.concatenate(([self.sample[0]], np.diff(self.sample)))
279+
if len(self.sample) == 1:
280+
sampdiffs = np.array([self.sample[0]])
281+
elif len(self.sample) > 1:
282+
sampdiffs = np.concatenate(([self.sample[0]], np.diff(self.sample)))
283+
else:
284+
raise ValueError("The 'sample' field must be a numpy array with length greater than 0")
280285
if min(self.sample) < 0 :
281286
raise ValueError("The 'sample' field must only contain non-negative integers")
282287
if min(sampdiffs) < 0 :
@@ -621,7 +626,10 @@ def calc_core_bytes(self):
621626
Convert all used annotation fields into bytes to write
622627
"""
623628
# The difference sample to write
624-
sampdiff = np.concatenate(([self.sample[0]], np.diff(self.sample)))
629+
if len(self.sample) == 1:
630+
sampdiff = np.array([self.sample[0]])
631+
else:
632+
sampdiff = np.concatenate(([self.sample[0]], np.diff(self.sample)))
625633

626634
# Create a copy of the annotation object with a
627635
# compact version of fields to write

0 commit comments

Comments
 (0)