som-shahlab/femr

Improve error handling for non-list labels in `LabeledPatients`

scottfleming opened this issue · 0 comments

Describe the bug

If you create a LabeledPatients object that maps from patient ID's to labels rather than mapping from patient ID's to lists of labels then there is no error on instantiation but the subsequent error message is opaque.

Steps to reproduce the bug

labels = femr.labelers.LabeledPatients({0: femr.labelers.Label(time=datetime.now(), value=False)})
labels.save('tmp.csv')

Expected results

There should be error handling on creation of femr.labelers.LabeledPatients. A message like, "Error: the label map you passed to instantiate the LabeledPatients object maps from integer patient ID's to Labels. It should map from integers to Iterables of Labels instead." would be helpful.

Actual results

*** TypeError: 'Label' object is not iterable