Skip to content

Commit cc8c9e9

Browse files
committed
add n_occurrences when summarizing annotation
1 parent 70b12f6 commit cc8c9e9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

wfdb/io/annotation.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ def sym_to_aux(self):
781781
def get_contained_labels(self, inplace=True):
782782
"""
783783
Get the set of unique labels contained in this annotation.
784-
Returns a pandas dataframe or sets the __contained__ labels
784+
Returns a pandas dataframe or sets the contained_labels
785785
attribute of the object.
786786
787787
@@ -827,19 +827,27 @@ def get_contained_labels(self, inplace=True):
827827
if self.label_store is not None:
828828
index_vals = set(self.label_store)
829829
reset_index = False
830+
counts = np.unique(self.label_store, return_counts=True)
830831
elif self.symbol is not None:
831832
index_vals = set(self.symbol)
832833
label_map.set_index(label_map['symbol'].values, inplace=True)
833834
reset_index = True
835+
counts = np.unique(self.symbol, return_counts=True)
834836
elif self.description is not None:
835837
index_vals = set(self.description)
836838
label_map.set_index(label_map['description'].values, inplace=True)
837839
reset_index = True
840+
counts = np.unique(self.description, return_counts=True)
838841
else:
839842
raise Exception('No annotation labels contained in object')
840843

841844
contained_labels = label_map.loc[index_vals, :]
842845

846+
# Add the counts
847+
for i in range(len(counts[0])):
848+
contained_labels.loc[counts[0][i], 'n_occurrences'] = counts[1][i]
849+
contained_labels['n_occurrences'] = pd.to_numeric(contained_labels['n_occurrences'], downcast='integer')
850+
843851
if reset_index:
844852
contained_labels.set_index(contained_labels['label_store'].values,
845853
inplace=True)
@@ -1220,7 +1228,7 @@ def rdann(record_name, extension, sampfrom=0, sampto=None, shift_samps=False,
12201228
If True, assign a summary table of the set of annotation labels
12211229
contained in the file to the 'contained_labels' attribute of the
12221230
returned object. This table will contain the columns:
1223-
['label_store', 'symbol', 'description', 'n_occurences']
1231+
['label_store', 'symbol', 'description', 'n_occurrences']
12241232
12251233
Returns
12261234
-------

0 commit comments

Comments
 (0)