From bc38b7e4f3569cada921365dacee01031ff890c3 Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Wed, 26 Aug 2026 19:42:06 +1000 Subject: [PATCH 01/14] add exclude parameter to get_data(), defaults to 'bad' --- mne/io/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mne/io/base.py b/mne/io/base.py index 79096cafaa3..f92a8d43704 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -944,6 +944,7 @@ def __setitem__(self, item, value): def get_data( self, picks: str | np.ndarray | slice | None = None, + exclude: list[str] | Literal["bads"] = "bads", start: int = 0, stop: int | None = None, reject_by_annotation: Literal["omit", "NaN"] | None = None, @@ -959,6 +960,9 @@ def get_data( Parameters ---------- %(picks_all)s + %(exclude_spectrum_get_data)s + + .. versionadded:: 1.13 start : int The first sample to include. Defaults to 0. stop : int | None @@ -1001,7 +1005,7 @@ def get_data( stop, types=("int-like", None), item_name="stop", type_name="int, None" ) - picks = _picks_to_idx(self.info, picks, "all", exclude=()) + picks = _picks_to_idx(self.info, picks, "all", exclude=exclude) # Get channel factors for conversion into specified unit # (vector of ones if no conversion needed) From 574a6d7ac561ad1985de50fb9c8f05e4461ed83b Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Wed, 26 Aug 2026 21:22:03 +1000 Subject: [PATCH 02/14] added exclude param to get_data() with default 'bads' --- mne/evoked.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mne/evoked.py b/mne/evoked.py index 01fac80a46e..1d233b543c2 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -239,6 +239,7 @@ def data(self, data: np.ndarray) -> None: def get_data( self, picks: str | np.ndarray | slice | None = None, + exclude: list[str] | Literal["bads"] = "bads", units: str | dict | None = None, tmin: float | None = None, tmax: float | None = None, @@ -248,6 +249,9 @@ def get_data( Parameters ---------- %(picks_all)s + %(exclude_spectrum_get_data)s + + .. versionadded:: 1.13 %(units)s tmin : float | None Start time of data to get in seconds. @@ -266,7 +270,7 @@ def get_data( # Avoid circular import from .io.base import _get_ch_factors - picks = _picks_to_idx(self.info, picks, "all", exclude=()) + picks = _picks_to_idx(self.info, picks, "all", exclude=exclude) start, stop = self._handle_tmin_tmax(tmin, tmax) From d700a4af7905f1e4ac6ad946722c992e67a18a5f Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Wed, 26 Aug 2026 21:23:17 +1000 Subject: [PATCH 03/14] added exclude param to get_data() with default 'bads' --- mne/epochs.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mne/epochs.py b/mne/epochs.py index fa0292041b1..a89284eb9cf 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -1720,6 +1720,7 @@ def _get_data( self, out=True, picks=None, + exclude="bads", item=None, *, units=None, @@ -1737,6 +1738,9 @@ def _get_data( Return the data. Setting this to False is used to reject bad epochs without caching all the data, which saves memory. %(picks_all)s + %(exclude_spectrum_get_data)s + + .. versionadded:: 1.13 item : slice | array-like | str | list | None See docstring of get_data method. %(units)s @@ -1805,7 +1809,7 @@ def _get_data( orig_picks = picks if orig_picks is None: - picks = _picks_to_idx(self.info, picks, "all", exclude=()) + picks = _picks_to_idx(self.info, picks, "all", exclude=exclude) else: picks = _picks_to_idx(self.info, picks) @@ -1986,6 +1990,7 @@ def _detrend_picks(self): def get_data( self, picks: str | np.ndarray | slice | None = None, + exclude: list[str] | Literal["bads"] = "bads", item: slice | np.ndarray | str | list | None = None, units: str | dict | None = None, tmin: int | float | None = None, @@ -1999,6 +2004,9 @@ def get_data( Parameters ---------- %(picks_all)s + %(exclude_spectrum_get_data)s + + .. versionadded:: 1.13 item : slice | array-like | str | list | None The items to get. See :meth:`mne.Epochs.__getitem__` for a description of valid options. This can be substantially faster From 7707bc628590e6592af22840651e99e7c8072b6a Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 26 Aug 2026 12:06:11 +0000 Subject: [PATCH 04/14] [autofix.ci] apply automated fixes --- mne/io/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/io/base.py b/mne/io/base.py index db86a4190f5..b4634a92cbc 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -1004,7 +1004,7 @@ def get_data( _validate_type( stop, types=("int-like", None), item_name="stop", type_name="int, None" ) - + if picks is None: # Fast lane: picks=None resolves to arange directly. # Benchmark (300 s recording): stops a 600 KB time-axis From e7f9de44515f61b3781f7a6eafa205c693aebd6f Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Wed, 26 Aug 2026 22:29:07 +1000 Subject: [PATCH 05/14] add changelog entry --- doc/changes/dev/14225.newfeature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/dev/14225.newfeature.rst diff --git a/doc/changes/dev/14225.newfeature.rst b/doc/changes/dev/14225.newfeature.rst new file mode 100644 index 00000000000..c81ee2d528b --- /dev/null +++ b/doc/changes/dev/14225.newfeature.rst @@ -0,0 +1 @@ +Add ``exclude`` parameter to :meth:`mne.io.Raw.get_data`, :meth:`mne.Epochs.get_data`, and :meth:`mne.Evoked.get_data` by `Carina Forster`_. From a1eeae4cb9a3e4164858688104a798c3120f7b20 Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Wed, 26 Aug 2026 23:00:11 +1000 Subject: [PATCH 06/14] fixed bug --- mne/epochs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mne/epochs.py b/mne/epochs.py index f114b12f145..36568555705 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -2052,7 +2052,13 @@ def get_data( when possible when ``copy=False``. """ return self._get_data( - picks=picks, item=item, units=units, tmin=tmin, tmax=tmax, copy=copy + picks=picks, + exclude=exclude, + item=item, + units=units, + tmin=tmin, + tmax=tmax, + copy=copy, ) @verbose From dfc6f3995f73b340a8a49ae201a03e509fafe608 Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Thu, 27 Aug 2026 00:45:22 +1000 Subject: [PATCH 07/14] clean up order and defaults --- mne/epochs.py | 16 +++++++++------- mne/evoked.py | 8 ++++---- mne/io/base.py | 8 ++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/mne/epochs.py b/mne/epochs.py index 36568555705..1b2dd8ead0e 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -1721,9 +1721,9 @@ def _get_data( self, out=True, picks=None, - exclude="bads", item=None, *, + exclude=(), units=None, tmin=None, tmax=None, @@ -1739,11 +1739,11 @@ def _get_data( Return the data. Setting this to False is used to reject bad epochs without caching all the data, which saves memory. %(picks_all)s - %(exclude_spectrum_get_data)s - - .. versionadded:: 1.13 item : slice | array-like | str | list | None See docstring of get_data method. + %(exclude_spectrum_get_data)s + + .. versionadded:: 1.13 %(units)s tmin : int | float | None Start time of data to get in seconds. @@ -1991,12 +1991,12 @@ def _detrend_picks(self): def get_data( self, picks: str | np.ndarray | slice | None = None, - exclude: list[str] | Literal["bads"] = "bads", item: slice | np.ndarray | str | list | None = None, units: str | dict | None = None, tmin: int | float | None = None, tmax: int | float | None = None, *, + exclude: list[str] | Literal["bads"] | tuple = (), copy: bool = True, verbose: bool | str | int | None = None, ) -> np.ndarray: @@ -2005,9 +2005,7 @@ def get_data( Parameters ---------- %(picks_all)s - %(exclude_spectrum_get_data)s - .. versionadded:: 1.13 item : slice | array-like | str | list | None The items to get. See :meth:`mne.Epochs.__getitem__` for a description of valid options. This can be substantially faster @@ -2027,6 +2025,10 @@ def get_data( End time of data to get in seconds. .. versionadded:: 0.24.0 + + %(exclude_spectrum_get_data)s + + .. versionadded:: 1.13 copy : bool Whether to return a copy of the object's data, or (if possible) a view. See :ref:`the NumPy docs ` for an diff --git a/mne/evoked.py b/mne/evoked.py index 1d233b543c2..30251706cfa 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -239,24 +239,24 @@ def data(self, data: np.ndarray) -> None: def get_data( self, picks: str | np.ndarray | slice | None = None, - exclude: list[str] | Literal["bads"] = "bads", units: str | dict | None = None, tmin: float | None = None, tmax: float | None = None, + exclude: list[str] | Literal["bads"] | tuple = (), ) -> np.ndarray: """Get evoked data as 2D array. Parameters ---------- %(picks_all)s - %(exclude_spectrum_get_data)s - - .. versionadded:: 1.13 %(units)s tmin : float | None Start time of data to get in seconds. tmax : float | None End time of data to get in seconds. + %(exclude_spectrum_get_data)s + + .. versionadded:: 1.13 Returns ------- diff --git a/mne/io/base.py b/mne/io/base.py index b4634a92cbc..c6cc90bc49e 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -944,13 +944,13 @@ def __setitem__(self, item, value): def get_data( self, picks: str | np.ndarray | slice | None = None, - exclude: list[str] | Literal["bads"] = "bads", start: int = 0, stop: int | None = None, reject_by_annotation: Literal["omit", "NaN"] | None = None, return_times: bool = False, units: str | dict | None = None, *, + exclude: list[str] | Literal["bads"] | tuple = (), tmin: int | float | None = None, tmax: int | float | None = None, verbose: bool | str | int | None = None, @@ -960,9 +960,6 @@ def get_data( Parameters ---------- %(picks_all)s - %(exclude_spectrum_get_data)s - - .. versionadded:: 1.13 start : int The first sample to include. Defaults to 0. stop : int | None @@ -975,6 +972,9 @@ def get_data( return_times : bool Whether to return times as well. Defaults to False. %(units)s + %(exclude_spectrum_get_data)s + + .. versionadded:: 1.13 tmin : int | float | None Start time of data to get in seconds. The ``tmin`` parameter is ignored if the ``start`` parameter is bigger than 0. From c80978985b69d75499acdea069cfbfc81c360eab Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Thu, 27 Aug 2026 22:06:08 +1000 Subject: [PATCH 08/14] fixed docstring for base --- mne/io/base.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mne/io/base.py b/mne/io/base.py index c6cc90bc49e..f28b8df61bd 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -972,7 +972,12 @@ def get_data( return_times : bool Whether to return times as well. Defaults to False. %(units)s - %(exclude_spectrum_get_data)s + exclude : list[str] | Literal["bads"] | tuple = () + Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are + excluded; pass an empty list or tuple (the default) to include all + channels. Note: ``exclude`` is currently only applied when ``picks`` + is not ``None``; it is ignored when ``picks=None`` (to be fixed in a + future release). .. versionadded:: 1.13 tmin : int | float | None From 775ab95b0dd87d6c1d3dc9a9dcfcfaedef16d70f Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Thu, 27 Aug 2026 22:11:11 +1000 Subject: [PATCH 09/14] updated docstrings --- mne/epochs.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mne/epochs.py b/mne/epochs.py index 1b2dd8ead0e..2ff960ae052 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -1741,9 +1741,14 @@ def _get_data( %(picks_all)s item : slice | array-like | str | list | None See docstring of get_data method. - %(exclude_spectrum_get_data)s + exclude : list[str] | Literal["bads"] | tuple = () + Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are + excluded; pass an empty list or tuple (the default) to include all + channels. Note: ``exclude`` is currently only applied when ``picks`` + is ``None``; it is ignored when ``picks!=None`` (to be fixed in a + future release). - .. versionadded:: 1.13 + .. versionadded:: 1.13 %(units)s tmin : int | float | None Start time of data to get in seconds. @@ -2026,7 +2031,12 @@ def get_data( .. versionadded:: 0.24.0 - %(exclude_spectrum_get_data)s + exclude : list[str] | Literal["bads"] | tuple = () + Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are + excluded; pass an empty list or tuple (the default) to include all + channels. Note: ``exclude`` is currently only applied when ``picks`` + is ``None``; it is ignored when ``picks!=None`` (to be fixed in a + future release). .. versionadded:: 1.13 copy : bool From bfcc196b9558d22b4515033eb6e3593f657b64d5 Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Thu, 27 Aug 2026 22:13:57 +1000 Subject: [PATCH 10/14] update docstrings --- mne/evoked.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mne/evoked.py b/mne/evoked.py index 30251706cfa..3d104e3f42e 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -254,7 +254,10 @@ def get_data( Start time of data to get in seconds. tmax : float | None End time of data to get in seconds. - %(exclude_spectrum_get_data)s + exclude : list[str] | Literal["bads"] | tuple = () + Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are + excluded; pass an empty list or tuple (the default) to include all + channels. .. versionadded:: 1.13 From b086466ebabb876870a2822d916a4e0a1491fc21 Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Thu, 27 Aug 2026 22:44:34 +1000 Subject: [PATCH 11/14] fix docstring --- mne/io/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/io/base.py b/mne/io/base.py index f28b8df61bd..96c276e3db3 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -972,7 +972,7 @@ def get_data( return_times : bool Whether to return times as well. Defaults to False. %(units)s - exclude : list[str] | Literal["bads"] | tuple = () + exclude : list[str] | Literal["bads"] Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are excluded; pass an empty list or tuple (the default) to include all channels. Note: ``exclude`` is currently only applied when ``picks`` From 58f1c8eedcb983dd3f355bac595641a68eeebc46 Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Thu, 27 Aug 2026 22:55:56 +1000 Subject: [PATCH 12/14] fixed docstring bug --- mne/epochs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mne/epochs.py b/mne/epochs.py index 2ff960ae052..b159546e195 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -1741,7 +1741,7 @@ def _get_data( %(picks_all)s item : slice | array-like | str | list | None See docstring of get_data method. - exclude : list[str] | Literal["bads"] | tuple = () + exclude : list[str] | Literal["bads"] Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are excluded; pass an empty list or tuple (the default) to include all channels. Note: ``exclude`` is currently only applied when ``picks`` @@ -2031,7 +2031,7 @@ def get_data( .. versionadded:: 0.24.0 - exclude : list[str] | Literal["bads"] | tuple = () + exclude : list[str] | Literal["bads"] Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are excluded; pass an empty list or tuple (the default) to include all channels. Note: ``exclude`` is currently only applied when ``picks`` From d71534ab1c3de4baa208392a1620da317dcb2744 Mon Sep 17 00:00:00 2001 From: CarinaFo Date: Thu, 27 Aug 2026 22:57:03 +1000 Subject: [PATCH 13/14] fix docstring bug --- mne/evoked.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/evoked.py b/mne/evoked.py index 3d104e3f42e..fcfac17670e 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -254,7 +254,7 @@ def get_data( Start time of data to get in seconds. tmax : float | None End time of data to get in seconds. - exclude : list[str] | Literal["bads"] | tuple = () + exclude : list[str] | Literal["bads"] Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are excluded; pass an empty list or tuple (the default) to include all channels. From f51f7e053bdf40b894333aca70f94af00b82d85f Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 28 Aug 2026 05:03:50 -0400 Subject: [PATCH 14/14] Apply suggestions from code review Co-authored-by: Eric Larson --- mne/epochs.py | 2 -- mne/io/base.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/mne/epochs.py b/mne/epochs.py index b159546e195..0fedc8dd41e 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -2010,7 +2010,6 @@ def get_data( Parameters ---------- %(picks_all)s - item : slice | array-like | str | list | None The items to get. See :meth:`mne.Epochs.__getitem__` for a description of valid options. This can be substantially faster @@ -2030,7 +2029,6 @@ def get_data( End time of data to get in seconds. .. versionadded:: 0.24.0 - exclude : list[str] | Literal["bads"] Channels to exclude. If ``'bads'``, channels in ``info['bads']`` are excluded; pass an empty list or tuple (the default) to include all diff --git a/mne/io/base.py b/mne/io/base.py index 96c276e3db3..a2bf7db6988 100644 --- a/mne/io/base.py +++ b/mne/io/base.py @@ -979,7 +979,7 @@ def get_data( is not ``None``; it is ignored when ``picks=None`` (to be fixed in a future release). - .. versionadded:: 1.13 + .. versionadded:: 1.13 tmin : int | float | None Start time of data to get in seconds. The ``tmin`` parameter is ignored if the ``start`` parameter is bigger than 0.