Skip to content

Commit f9e797d

Browse files
committed
Fixes Pandas .loc update for annotations #255
Fixes the deprecation of .loc being used with missing labels and replaces it with the suggested .reindex(). Fixes #255. Fixes TravisCI error
1 parent 4d4c354 commit f9e797d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

wfdb/io/annotation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,10 @@ def convert_label_attribute(self, source_field, target_field, inplace=True,
12041204
label_map = self.create_label_map(inplace=False)
12051205
label_map.set_index(label_map[source_field].values, inplace=True)
12061206

1207-
target_item = label_map.loc[getattr(self, source_field), target_field].values
1207+
try:
1208+
target_item = label_map.loc[getattr(self, source_field), target_field].values
1209+
except KeyError:
1210+
target_item = label_map.reindex(index=getattr(self, source_field), columns=[target_field]).values.flatten()
12081211

12091212
if target_field != 'label_store':
12101213
# Should already be int64 dtype if target is label_store

0 commit comments

Comments
 (0)