vocalpy / crowsetta

A tool to work with any format for annotating vocalizations
https://crowsetta.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
49 stars 3 forks source link

ENH: Gracefully handle annotation files with no annotated segments/boxes #264

Open NickleDave opened 5 months ago

NickleDave commented 5 months ago

Right now crowsetta does not have any logic for handle annotation files that have no annotations, i.e. that are empty.

This is kind of an edge case, since it's very likely that if you are already loading your annotations into Python from another tool you have specifically annotated what you are interested in.

But it can still happen: e.g. when creating clips of an existing dataset and re-making the annotations for the clips from an existing set of annotations, we can end up with a clip that has no segments in it.

Currently this raises a pretty inscrutable error from pandera.errors.SchemaError about "expected 'type' but got object" where 'type' will be the expected type for some column.

We should instead do a try-catch and check if the dataframe is empty (df = pd.load_csv(annot_path); if len(df) == 0: pass), and if it is, return an empty instance of the class. If not, re-raise the error.