Skip to content

Commit ba127f7

Browse files
authored
MAINT: Replace in1d with isin (#11994)
1 parent aae0122 commit ba127f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+141
-113
lines changed

examples/visualization/evoked_topomap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
("MEG 2411", "MEG 2421"),
149149
("MEG 1621"),
150150
]
151-
_channels = [np.in1d(evoked.ch_names, ch) for ch in significant_channels]
151+
_channels = [np.isin(evoked.ch_names, ch) for ch in significant_channels]
152152

153153
mask = np.zeros(evoked.data.shape, dtype="bool")
154154
for _chs, _time in zip(_channels, _times):

mne/_freesurfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def get_volume_labels_from_aseg(mgz_fname, return_colors=False, atlas_ids=None):
249249
elif return_colors:
250250
raise ValueError("return_colors must be False if atlas_ids are " "provided")
251251
# restrict to the ones in the MRI, sorted by label name
252-
keep = np.in1d(list(atlas_ids.values()), want)
252+
keep = np.isin(list(atlas_ids.values()), want)
253253
keys = sorted(
254254
(key for ki, key in enumerate(atlas_ids.keys()) if keep[ki]),
255255
key=lambda x: atlas_ids[x],

mne/beamformer/tests/test_dics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _simulate_data(fwd, idx): # Somewhere on the frontal lobe by default
108108
csd = csd_morlet(epochs, frequencies=[10, 20], n_cycles=[5, 10], decim=5)
109109

110110
labels = mne.read_labels_from_annot("sample", hemi="lh", subjects_dir=subjects_dir)
111-
label = [label for label in labels if np.in1d(source_vertno, label.vertices)[0]]
111+
label = [label for label in labels if np.isin(source_vertno, label.vertices)]
112112
assert len(label) == 1
113113
label = label[0]
114114
vertices = np.intersect1d(label.vertices, fwd["src"][0]["vertno"])

mne/beamformer/tests/test_lcmv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_lcmv_vector():
193193

194194
# Figure out our indices
195195
mask = np.concatenate(
196-
[np.in1d(s["vertno"], v) for s, v in zip(forward["src"], vertices)]
196+
[np.isin(s["vertno"], v) for s, v in zip(forward["src"], vertices)]
197197
)
198198
mapping = np.where(mask)[0]
199199
assert_array_equal(source_rr, forward["source_rr"][mapping])

mne/channels/interpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def _interpolate_bads_meeg(
212212
picks_bad = pick_channels(inst.info["ch_names"], bads_type, exclude=[])
213213
if ch_type == "eeg":
214214
picks_to = picks_type
215-
bad_sel = np.in1d(picks_type, picks_bad)
215+
bad_sel = np.isin(picks_type, picks_bad)
216216
else:
217217
picks_to = picks_bad
218218
bad_sel = slice(None)

mne/chpi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ def _setup_ext_proj(info, ext_order):
727727
dict(origin=(0.0, 0.0, 0.0), int_order=0, ext_order=ext_order), mf_coils
728728
).T
729729
out_removes = _regularize_out(0, 1, mag_or_fine, [])
730-
ext = ext[~np.in1d(np.arange(len(ext)), out_removes)]
730+
ext = ext[~np.isin(np.arange(len(ext)), out_removes)]
731731
ext = orth(ext.T).T
732732
assert ext.shape[1] == len(meg_picks)
733733
proj = Projection(

mne/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def pytest_configure(config):
167167
ignore:mne\.io\.pick.channel_indices_by_type is deprecated.*:
168168
# Windows CIs using MESA get this
169169
ignore:Mesa version 10\.2\.4 is too old for translucent.*:RuntimeWarning
170+
# Matplotlib <-> NumPy 2.0
171+
ignore:`row_stack` alias is deprecated.*:DeprecationWarning
170172
""" # noqa: E501
171173
for warning_line in warning_lines.split("\n"):
172174
warning_line = warning_line.strip()

mne/cov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def compute_raw_covariance(
709709
if picks is None:
710710
# Need to include all channels e.g. if eog rejection is to be used
711711
picks = np.arange(raw.info["nchan"])
712-
pick_mask = np.in1d(picks, _pick_data_channels(raw.info, with_ref_meg=False))
712+
pick_mask = np.isin(picks, _pick_data_channels(raw.info, with_ref_meg=False))
713713
else:
714714
pick_mask = slice(None)
715715
picks = _picks_to_idx(raw.info, picks)

mne/epochs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def __init__(
503503
del events
504504

505505
values = list(self.event_id.values())
506-
selected = np.where(np.in1d(self.events[:, 2], values))[0]
506+
selected = np.where(np.isin(self.events[:, 2], values))[0]
507507
if selection is None:
508508
selection = selected
509509
else:
@@ -538,7 +538,7 @@ def __init__(
538538
)
539539

540540
# then subselect
541-
sub = np.where(np.in1d(selection, self.selection))[0]
541+
sub = np.where(np.isin(selection, self.selection))[0]
542542
if isinstance(metadata, list):
543543
metadata = [metadata[s] for s in sub]
544544
elif metadata is not None:
@@ -2849,7 +2849,7 @@ def _ensure_list(x):
28492849
id_to_name_map = {v: k for k, v in event_id.items()}
28502850

28512851
# Only keep events that are of interest
2852-
events = events[np.in1d(events[:, 2], list(event_id.values()))]
2852+
events = events[np.isin(events[:, 2], list(event_id.values()))]
28532853
events_df = events_df.loc[events_df["id"].isin(event_id.values()), :]
28542854

28552855
# Prepare & condition the metadata DataFrame
@@ -2954,7 +2954,7 @@ def _ensure_list(x):
29542954
event_id_timelocked = {
29552955
name: val for name, val in event_id.items() if name in row_events
29562956
}
2957-
events = events[np.in1d(events[:, 2], list(event_id_timelocked.values()))]
2957+
events = events[np.isin(events[:, 2], list(event_id_timelocked.values()))]
29582958
metadata = metadata.loc[metadata["event_name"].isin(event_id_timelocked)]
29592959
assert len(events) == len(metadata)
29602960
event_id = event_id_timelocked
@@ -3302,7 +3302,7 @@ def __init__(
33023302
self._do_baseline = True
33033303
if (
33043304
len(events)
3305-
!= np.in1d(self.events[:, 2], list(self.event_id.values())).sum()
3305+
!= np.isin(self.events[:, 2], list(self.event_id.values())).sum()
33063306
):
33073307
raise ValueError(
33083308
"The events must only contain event numbers from " "event_id"

mne/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ def shift_time_events(events, ids, tshift, sfreq):
914914
if ids is None:
915915
mask = slice(None)
916916
else:
917-
mask = np.in1d(events[:, 2], ids)
917+
mask = np.isin(events[:, 2], ids)
918918
events[mask, 0] += int(tshift * sfreq)
919919

920920
return events

0 commit comments

Comments
 (0)