From 581aea419c171391f1be68f2d82ae4e2b0cd1d35 Mon Sep 17 00:00:00 2001 From: Scott Huberty Date: Thu, 15 Oct 2026 10:14:49 -0700 Subject: [PATCH 1/3] fix for neo 0.14.6 --- mne/io/neuralynx/neuralynx.py | 21 ++++++++++++++++----- mne/io/neuralynx/tests/test_neuralynx.py | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/mne/io/neuralynx/neuralynx.py b/mne/io/neuralynx/neuralynx.py index 4de7288db04..41767c35e3f 100644 --- a/mne/io/neuralynx/neuralynx.py +++ b/mne/io/neuralynx/neuralynx.py @@ -106,13 +106,21 @@ def read_raw_neuralynx( # Helper for neo change of exclude_filename -> exclude_filenames in 0.13.2 -def _exclude_kwarg(exclude_fnames): +def _neo_kwargs(exclude_fnames): from neo.io import NeuralynxIO + kwargs = {} key = "exclude_filename" - if "exclude_filenames" in inspect.getfullargspec(NeuralynxIO).args: + params = inspect.signature(NeuralynxIO) + if "exclude_filenames" in params.parameters: key += "s" - return {key: exclude_fnames} + kwargs[key] = exclude_fnames + + # Introduced in neo version 0.14.6 + if "gap_tolerance_ms" in params.parameters: + # As recommended by neo API documentation. This restores the old behavior + kwargs.update({"gap_tolerance_ms": 0.0}) + return kwargs @fill_doc_static() @@ -146,9 +154,11 @@ def __init__( logger.info("Ignoring .ncs files:\n" + "\n".join(exclude_fnames)) + # Gap handling and filename excluding + neo_kwargs = _neo_kwargs(exclude_fnames) # get basic file info from header, throw Error if NeuralynxIO can't parse try: - nlx_reader = NeuralynxIO(dirname=fname, **_exclude_kwarg(exclude_fnames)) + nlx_reader = NeuralynxIO(dirname=fname, **neo_kwargs) except ValueError as e: # give a more informative error message and what the user can do about it if "Incompatible section structures across streams" in str(e): @@ -341,9 +351,10 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult): # quantities is a dependency of neo so we are guaranteed it exists from quantities import Hz + neo_kwargs = _neo_kwargs(self._raw_extras[0]["exclude_fnames"]) nlx_reader = NeuralynxIO( dirname=self.filenames[fi], - **_exclude_kwarg(self._raw_extras[0]["exclude_fnames"]), + **neo_kwargs, ) neo_block = nlx_reader.read(lazy=True) diff --git a/mne/io/neuralynx/tests/test_neuralynx.py b/mne/io/neuralynx/tests/test_neuralynx.py index 64f940f1312..9787480001e 100644 --- a/mne/io/neuralynx/tests/test_neuralynx.py +++ b/mne/io/neuralynx/tests/test_neuralynx.py @@ -13,7 +13,7 @@ from mne.datasets.testing import data_path, requires_testing_data from mne.io import read_raw_neuralynx -from mne.io.neuralynx.neuralynx import _exclude_kwarg +from mne.io.neuralynx.neuralynx import _neo_kwargs from mne.io.tests.test_raw import _test_raw_reader testing_path = data_path(download=False) / "neuralynx" @@ -150,7 +150,7 @@ def test_neuralynx(): mne_y = raw.get_data() # in V # ==== NeuralynxIO ==== # - nlx_reader = NeuralynxIO(dirname=testing_path, **_exclude_kwarg(excluded_ncs_files)) + nlx_reader = NeuralynxIO(dirname=testing_path, **_neo_kwargs(excluded_ncs_files)) bl = nlx_reader.read( lazy=False ) # read a single block which contains the data split in segments From 0f42d553fa1e8cd40e0f333e68115b1a6f39de4e Mon Sep 17 00:00:00 2001 From: Scott Huberty Date: Thu, 15 Oct 2026 10:23:21 -0700 Subject: [PATCH 2/3] changelog --- doc/changes/dev/14423.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/dev/14423.bugfix.rst diff --git a/doc/changes/dev/14423.bugfix.rst b/doc/changes/dev/14423.bugfix.rst new file mode 100644 index 00000000000..f1ea24a55ad --- /dev/null +++ b/doc/changes/dev/14423.bugfix.rst @@ -0,0 +1 @@ +Fix MNE-Python readers for Neuralynx recordings with gaps, following changes in `Neo 0.14.6 `_ by `Scott Huberty`_ From 8a73ae200944761a8be3b9b280ba1702fc0acb95 Mon Sep 17 00:00:00 2001 From: Scott Huberty Date: Thu, 15 Oct 2026 10:26:18 -0700 Subject: [PATCH 3/3] ping