From dbeea81c8f5e78bacae3e5c68df7cb9f65060210 Mon Sep 17 00:00:00 2001 From: Scott Huberty Date: Wed, 13 Nov 2024 09:03:02 -0800 Subject: [PATCH] FIX: early return in find_breaks if no annotations in raw --- pylossless/pipeline.py | 3 +++ pylossless/tests/test_pipeline.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pylossless/pipeline.py b/pylossless/pipeline.py index 1387a0a..c03c5e5 100644 --- a/pylossless/pipeline.py +++ b/pylossless/pipeline.py @@ -718,6 +718,9 @@ def find_breaks(self): """ if "find_breaks" not in self.config or not self.config["find_breaks"]: return + if not self.raw.annotations: + logger.debug("No annotations found in raw object. Skipping find_breaks.") + return breaks = annotate_break(self.raw, **self.config["find_breaks"]) self.raw.set_annotations(breaks + self.raw.annotations) diff --git a/pylossless/tests/test_pipeline.py b/pylossless/tests/test_pipeline.py index cc76d21..4476bda 100644 --- a/pylossless/tests/test_pipeline.py +++ b/pylossless/tests/test_pipeline.py @@ -43,6 +43,9 @@ def test_find_breaks(logging): pipeline.find_breaks(message="Looking for break periods between tasks") else: pipeline.find_breaks() + # Now explicitly remove annotations and make sure we avoid MNE's error. + pipeline.raw.set_annotations(None) + pipeline.find_breaks() Path(config_fname).unlink() # delete config file