From bb04a62c1cecfb19d5c5399aef75eb6bf54b0dbf Mon Sep 17 00:00:00 2001 From: Bru Date: Tue, 3 Feb 2026 16:43:22 +0100 Subject: [PATCH 1/2] updating the _snirf test and the test --- doc/changes/dev/13627.bugfix.rst | 1 + mne/io/snirf/_snirf.py | 5 +++++ mne/io/snirf/tests/test_snirf.py | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 doc/changes/dev/13627.bugfix.rst diff --git a/doc/changes/dev/13627.bugfix.rst b/doc/changes/dev/13627.bugfix.rst new file mode 100644 index 00000000000..883ac03c2da --- /dev/null +++ b/doc/changes/dev/13627.bugfix.rst @@ -0,0 +1 @@ +Fix :func:`mne.io.read_raw_snirf` raising ``TypeError`` when ``landmarkLabels`` is empty or scalar, by `Bruno Aristimunha`_. diff --git a/mne/io/snirf/_snirf.py b/mne/io/snirf/_snirf.py index cfb9c8f71e2..020e55f4d91 100644 --- a/mne/io/snirf/_snirf.py +++ b/mne/io/snirf/_snirf.py @@ -388,6 +388,11 @@ def natural_keys(text): diglocs = np.array(dat.get("/nirs/probe/landmarkPos3D")) diglocs /= length_scaling digname = np.array(dat.get("/nirs/probe/landmarkLabels")) + # Handle empty or scalar landmarkLabels (see gh-13627) + if digname.ndim == 0 or digname.size == 0: + digname = [] + else: + digname = _correct_shape(digname) nasion, lpa, rpa, hpi = None, None, None, None extra_ps = dict() for idx, dign in enumerate(digname): diff --git a/mne/io/snirf/tests/test_snirf.py b/mne/io/snirf/tests/test_snirf.py index 24f6f1174c7..aaec3ea20cf 100644 --- a/mne/io/snirf/tests/test_snirf.py +++ b/mne/io/snirf/tests/test_snirf.py @@ -284,6 +284,33 @@ def test_snirf_nonstandard(tmp_path): f.create_dataset("nirs/metaDataTags/MNE_coordFrame", data=[1]) +@requires_testing_data +def test_snirf_empty_landmark_labels(tmp_path): + """Test reading SNIRF files with empty landmarkLabels (gh-13627).""" + shutil.copy(sfnirs_homer_103_wShort, tmp_path / "empty_labels.snirf") + fname = tmp_path / "empty_labels.snirf" + + # Modify file to have landmarkPos3D but empty/scalar landmarkLabels + with h5py.File(fname, "r+") as f: + # Remove existing landmark data if present + if "landmarkPos3D" in f["nirs/probe"]: + del f["nirs/probe/landmarkPos3D"] + if "landmarkLabels" in f["nirs/probe"]: + del f["nirs/probe/landmarkLabels"] + + # Add non-empty landmarkPos3D + f.create_dataset( + "nirs/probe/landmarkPos3D", + data=np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]]), + ) + # Add empty scalar landmarkLabels (this triggers the bug in gh-13627) + f.create_dataset("nirs/probe/landmarkLabels", data=b"") + + # This should not raise "TypeError: iteration over a 0-d array" + raw = read_raw_snirf(fname, preload=True) + assert raw.info["dig"] is not None + + @requires_testing_data def test_snirf_nirsport2(): """Test reading SNIRF files.""" From b97b9cc205850bfea7f45d1eb3f04fac5fd4ead8 Mon Sep 17 00:00:00 2001 From: Bru Date: Tue, 3 Feb 2026 16:46:51 +0100 Subject: [PATCH 2/2] DOC: Rename changelog to match PR number --- doc/changes/dev/{13627.bugfix.rst => 13628.bugfix.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/changes/dev/{13627.bugfix.rst => 13628.bugfix.rst} (100%) diff --git a/doc/changes/dev/13627.bugfix.rst b/doc/changes/dev/13628.bugfix.rst similarity index 100% rename from doc/changes/dev/13627.bugfix.rst rename to doc/changes/dev/13628.bugfix.rst