From ee171bb3a9d7d84495c7f220caa2a1da624648a5 Mon Sep 17 00:00:00 2001 From: ZIYI ZENG Date: Sat, 23 Nov 2024 15:03:06 +0800 Subject: [PATCH 1/3] Fix: update cnt.py to check missing annotation Add missing annotation check when loading CNT file --- mne/io/cnt/cnt.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mne/io/cnt/cnt.py b/mne/io/cnt/cnt.py index bd5fb4c2f29..5a39a02a981 100644 --- a/mne/io/cnt/cnt.py +++ b/mne/io/cnt/cnt.py @@ -337,7 +337,8 @@ def _get_cnt_info(input_fname, eog, ecg, emg, misc, data_format, date_format, he n_samples = data_size // (n_bytes * n_channels) # See: PR #12393 annotations = _read_annotations_cnt(input_fname, data_format="int16") - if annotations.onset[-1] * sfreq > n_samples: + # fix for issue #12982 + if len(annotations) and annotations.onset[-1] * sfreq > n_samples: n_bytes = 4 n_samples = n_samples_header warn( From 4ef4613955bebf3ebead059a9334707f9f9e7e2e Mon Sep 17 00:00:00 2001 From: ZIYI ZENG Date: Sat, 23 Nov 2024 16:23:09 +0800 Subject: [PATCH 2/3] Fix: Index-error when loading CNT file --- doc/changes/devel/12986.bugfix.rst | 1 + doc/changes/names.inc | 1 + mne/io/cnt/cnt.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 doc/changes/devel/12986.bugfix.rst diff --git a/doc/changes/devel/12986.bugfix.rst b/doc/changes/devel/12986.bugfix.rst new file mode 100644 index 00000000000..5bacb548fdd --- /dev/null +++ b/doc/changes/devel/12986.bugfix.rst @@ -0,0 +1 @@ +Fix IndexError when loading CNT file does not have annotations, by :newcontrib:`Ziyi ZENG`. \ No newline at end of file diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 79fbe9b1236..ce2ff23d54a 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -319,3 +319,4 @@ .. _Yu-Han Luo: https://github.com/yh-luo .. _Zhi Zhang: https://github.com/tczhangzhi/ .. _Zvi Baratz: https://github.com/ZviBaratz +.. _Ziyi ZENG: https://github.com/ZiyiTsang diff --git a/mne/io/cnt/cnt.py b/mne/io/cnt/cnt.py index 5a39a02a981..16c074269bf 100644 --- a/mne/io/cnt/cnt.py +++ b/mne/io/cnt/cnt.py @@ -337,7 +337,7 @@ def _get_cnt_info(input_fname, eog, ecg, emg, misc, data_format, date_format, he n_samples = data_size // (n_bytes * n_channels) # See: PR #12393 annotations = _read_annotations_cnt(input_fname, data_format="int16") - # fix for issue #12982 + # See: PR #12986 if len(annotations) and annotations.onset[-1] * sfreq > n_samples: n_bytes = 4 n_samples = n_samples_header From 1598ed7b37b752617bcf4bb41fffd5655cb47101 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 23 Nov 2024 08:23:38 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/changes/names.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/names.inc b/doc/changes/names.inc index ce2ff23d54a..3dfc742b3b3 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -318,5 +318,5 @@ .. _Yousra Bekhti: https://www.linkedin.com/pub/yousra-bekhti/56/886/421 .. _Yu-Han Luo: https://github.com/yh-luo .. _Zhi Zhang: https://github.com/tczhangzhi/ -.. _Zvi Baratz: https://github.com/ZviBaratz .. _Ziyi ZENG: https://github.com/ZiyiTsang +.. _Zvi Baratz: https://github.com/ZviBaratz