diff --git a/doc/changes/devel/bugfix.rst b/doc/changes/devel/bugfix.rst new file mode 100644 index 00000000000..8c5ee5a6fca --- /dev/null +++ b/doc/changes/devel/bugfix.rst @@ -0,0 +1 @@ +Fix bug where :func:`mne.preprocessing.compute_proj_ecg` and :func:`mne.preprocessing.compute_proj_eog` could modify the default ``reject`` and ``flat`` arguments on multiple calls based on channel types present, by `Eric Larson`_. diff --git a/mne/_fiff/open.py b/mne/_fiff/open.py index 65a7bec33a8..5bfcb83a951 100644 --- a/mne/_fiff/open.py +++ b/mne/_fiff/open.py @@ -268,7 +268,7 @@ def show_fiff( return out -def _find_type(value, fmts=["FIFF_"], exclude=["FIFF_UNIT"]): +def _find_type(value, fmts=("FIFF_",), exclude=("FIFF_UNIT",)): """Find matching values.""" value = int(value) vals = [ diff --git a/mne/_fiff/pick.py b/mne/_fiff/pick.py index 86790e6e3e8..2722e91f517 100644 --- a/mne/_fiff/pick.py +++ b/mne/_fiff/pick.py @@ -259,7 +259,7 @@ def channel_type(info, idx): @verbose -def pick_channels(ch_names, include, exclude=[], ordered=None, *, verbose=None): +def pick_channels(ch_names, include, exclude=(), ordered=None, *, verbose=None): """Pick channels by names. Returns the indices of ``ch_names`` in ``include`` but not in ``exclude``. @@ -706,7 +706,7 @@ def _has_kit_refs(info, picks): @verbose def pick_channels_forward( - orig, include=[], exclude=[], ordered=None, copy=True, *, verbose=None + orig, include=(), exclude=(), ordered=None, copy=True, *, verbose=None ): """Pick channels from forward operator. @@ -797,8 +797,8 @@ def pick_types_forward( seeg=False, ecog=False, dbs=False, - include=[], - exclude=[], + include=(), + exclude=(), ): """Pick by channel type and names from a forward operator. @@ -893,7 +893,7 @@ def channel_indices_by_type(info, picks=None): @verbose def pick_channels_cov( - orig, include=[], exclude="bads", ordered=None, copy=True, *, verbose=None + orig, include=(), exclude="bads", ordered=None, copy=True, *, verbose=None ): """Pick channels from covariance matrix. diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index b403a0e6713..adfe63f93d9 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -438,8 +438,8 @@ def test_1020_selection(): raw = raw.rename_channels(dict(zip(raw.ch_names, montage.ch_names))) raw.set_montage(montage) - for input in ("a_string", 100, raw, [1, 2]): - pytest.raises(TypeError, make_1020_channel_selections, input) + for input_ in ("a_string", 100, raw, [1, 2]): + pytest.raises(TypeError, make_1020_channel_selections, input_) sels = make_1020_channel_selections(raw.info) # are all frontal channels placed before all occipital channels? diff --git a/mne/commands/mne_setup_source_space.py b/mne/commands/mne_setup_source_space.py index b5654ecab7f..f5f5dc8b343 100644 --- a/mne/commands/mne_setup_source_space.py +++ b/mne/commands/mne_setup_source_space.py @@ -120,7 +120,7 @@ def run(): subjects_dir = options.subjects_dir spacing = options.spacing ico = options.ico - oct = options.oct + oct_ = options.oct surface = options.surface n_jobs = options.n_jobs add_dist = options.add_dist @@ -130,20 +130,22 @@ def run(): overwrite = True if options.overwrite is not None else False # Parse source spacing option - spacing_options = [ico, oct, spacing] + spacing_options = [ico, oct_, spacing] n_options = len([x for x in spacing_options if x is not None]) + use_spacing = "oct6" if n_options > 1: raise ValueError("Only one spacing option can be set at the same time") elif n_options == 0: # Default to oct6 - use_spacing = "oct6" + pass elif n_options == 1: if ico is not None: use_spacing = "ico" + str(ico) - elif oct is not None: - use_spacing = "oct" + str(oct) + elif oct_ is not None: + use_spacing = "oct" + str(oct_) elif spacing is not None: use_spacing = spacing + del ico, oct_, spacing # Generate filename if fname is None: if subject_to is None: diff --git a/mne/cov.py b/mne/cov.py index 311121c8f87..7b9a4b24252 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -310,7 +310,7 @@ def __iadd__(self, cov): def plot( self, info, - exclude=[], + exclude=(), colorbar=True, proj=False, show_svd=True, diff --git a/mne/datasets/sleep_physionet/tests/test_physionet.py b/mne/datasets/sleep_physionet/tests/test_physionet.py index 08b13c832c7..7cf57632057 100644 --- a/mne/datasets/sleep_physionet/tests/test_physionet.py +++ b/mne/datasets/sleep_physionet/tests/test_physionet.py @@ -46,12 +46,12 @@ def _check_mocked_function_calls(mocked_func, call_fname_hash_pairs, base_path): # order. for idx, current in enumerate(call_fname_hash_pairs): _, call_kwargs = mocked_func.call_args_list[idx] - hash_type, hash = call_kwargs["known_hash"].split(":") + hash_type, hash_ = call_kwargs["known_hash"].split(":") assert call_kwargs["url"] == _get_expected_url(current["name"]), idx assert Path(call_kwargs["path"], call_kwargs["fname"]) == _get_expected_path( base_path, current["name"] ) - assert hash == current["hash"] + assert hash_ == current["hash"] assert hash_type == "sha1" diff --git a/mne/decoding/tests/test_ssd.py b/mne/decoding/tests/test_ssd.py index bdb3f74c545..e72e0ff81ad 100644 --- a/mne/decoding/tests/test_ssd.py +++ b/mne/decoding/tests/test_ssd.py @@ -19,7 +19,7 @@ def simulate_data( - freqs_sig=[9, 12], + freqs_sig=(9, 12), n_trials=100, n_channels=20, n_samples=500, diff --git a/mne/epochs.py b/mne/epochs.py index d1f76609356..2b437dca6b3 100644 --- a/mne/epochs.py +++ b/mne/epochs.py @@ -3662,7 +3662,7 @@ def _is_good( reject, flat, full_report=False, - ignore_chs=[], + ignore_chs=(), verbose=None, ): """Test if data segment e is good according to reject and flat. @@ -4631,7 +4631,7 @@ def make_fixed_length_epochs( reject_by_annotation=True, proj=True, overlap=0.0, - id=1, + id=1, # noqa: A002 verbose=None, ): """Divide continuous raw data into equal-sized consecutive epochs. diff --git a/mne/event.py b/mne/event.py index 6bb8a1f604a..cfc112a2e8c 100644 --- a/mne/event.py +++ b/mne/event.py @@ -925,7 +925,13 @@ def shift_time_events(events, ids, tshift, sfreq): @fill_doc def make_fixed_length_events( - raw, id=1, start=0, stop=None, duration=1.0, first_samp=True, overlap=0.0 + raw, + id=1, # noqa: A002 + start=0, + stop=None, + duration=1.0, + first_samp=True, + overlap=0.0, ): """Make a set of :term:`events` separated by a fixed duration. diff --git a/mne/evoked.py b/mne/evoked.py index a3f530076ac..c988368c314 100644 --- a/mne/evoked.py +++ b/mne/evoked.py @@ -549,7 +549,7 @@ def plot_topo( scalings=None, title=None, proj=False, - vline=[0.0], + vline=(0.0,), fig_background=None, merge_grads=False, legend=True, diff --git a/mne/export/_export.py b/mne/export/_export.py index 80a18d090d2..476a3f2f90a 100644 --- a/mne/export/_export.py +++ b/mne/export/_export.py @@ -211,9 +211,9 @@ def _infer_check_export_fmt(fmt, fname, supported_formats): if fmt not in supported_formats: supported = [] - for format, extensions in supported_formats.items(): + for fmt, extensions in supported_formats.items(): ext_str = ", ".join(f"*.{ext}" for ext in extensions) - supported.append(f"{format} ({ext_str})") + supported.append(f"{fmt} ({ext_str})") supported_str = ", ".join(supported) raise ValueError( diff --git a/mne/inverse_sparse/mxne_optim.py b/mne/inverse_sparse/mxne_optim.py index 5d785f5eec5..a4c63a557b5 100644 --- a/mne/inverse_sparse/mxne_optim.py +++ b/mne/inverse_sparse/mxne_optim.py @@ -799,7 +799,7 @@ def __call__(self, x): # noqa: D105 else: return np.hstack([x @ op for op in self.ops]) / np.sqrt(self.n_dicts) - def norm(self, z, ord=2): + def norm(self, z, ord=2): # noqa: A002 """Squared L2 norm if ord == 2 and L1 norm if order == 1.""" if ord not in (1, 2): raise ValueError( diff --git a/mne/io/bti/bti.py b/mne/io/bti/bti.py index 71c85880069..616602892dd 100644 --- a/mne/io/bti/bti.py +++ b/mne/io/bti/bti.py @@ -78,7 +78,7 @@ def __init__(self, target): def __enter__(self): # noqa: D105 return self.target - def __exit__(self, type, value, tb): # noqa: D105 + def __exit__(self, exception_type, value, tb): # noqa: D105 pass diff --git a/mne/io/curry/curry.py b/mne/io/curry/curry.py index 021bc729ebf..3b3d5e711d3 100644 --- a/mne/io/curry/curry.py +++ b/mne/io/curry/curry.py @@ -197,10 +197,10 @@ def _read_curry_parameters(fname): if any(var_name in line for var_name in var_names): key, val = line.replace(" ", "").replace("\n", "").split("=") param_dict[key.lower().replace("_", "")] = val - for type in CHANTYPES: - if "DEVICE_PARAMETERS" + CHANTYPES[type] + " START" in line: + for key, type_ in CHANTYPES.items(): + if f"DEVICE_PARAMETERS{type_} START" in line: data_unit = next(fid) - unit_dict[type] = ( + unit_dict[key] = ( data_unit.replace(" ", "").replace("\n", "").split("=")[-1] ) diff --git a/mne/io/edf/edf.py b/mne/io/edf/edf.py index 62987ac19fc..888db95c9a6 100644 --- a/mne/io/edf/edf.py +++ b/mne/io/edf/edf.py @@ -1454,7 +1454,9 @@ def _read_gdf_header(fname, exclude, include=None): def _check_stim_channel( - stim_channel, ch_names, tal_ch_names=["EDF Annotations", "BDF Annotations"] + stim_channel, + ch_names, + tal_ch_names=("EDF Annotations", "BDF Annotations"), ): """Check that the stimulus channel exists in the current datafile.""" DEFAULT_STIM_CH_NAMES = ["status", "trigger"] diff --git a/mne/io/fieldtrip/tests/helpers.py b/mne/io/fieldtrip/tests/helpers.py index 5ab02286b66..66cb582dde9 100644 --- a/mne/io/fieldtrip/tests/helpers.py +++ b/mne/io/fieldtrip/tests/helpers.py @@ -185,7 +185,7 @@ def get_epochs(system): else: event_id = [int(cfg_local["eventvalue"])] - event_id = [id for id in event_id if id in events[:, 2]] + event_id = [id_ for id_ in event_id if id_ in events[:, 2]] epochs = mne.Epochs( raw_data, diff --git a/mne/io/fieldtrip/tests/test_fieldtrip.py b/mne/io/fieldtrip/tests/test_fieldtrip.py index 0f66d1b1fae..811bfd0a269 100644 --- a/mne/io/fieldtrip/tests/test_fieldtrip.py +++ b/mne/io/fieldtrip/tests/test_fieldtrip.py @@ -254,18 +254,18 @@ def test_one_channel_elec_bug(version): @pytest.mark.filterwarnings("ignore:.*number of bytes.*:RuntimeWarning") @pytest.mark.parametrize("version", all_versions) @pytest.mark.parametrize("type", ["averaged", "epoched", "raw"]) -def test_throw_exception_on_cellarray(version, type): +def test_throw_exception_on_cellarray(version, type_): """Test for a meaningful exception when the data is a cell array.""" - fname = get_data_paths("cellarray") / f"{type}_{version}.mat" + fname = get_data_paths("cellarray") / f"{type_}_{version}.mat" info = get_raw_info("CNT") with pytest.raises( RuntimeError, match="Loading of data in cell arrays " "is not supported" ): - if type == "averaged": + if type_ == "averaged": mne.read_evoked_fieldtrip(fname, info) - elif type == "epoched": + elif type_ == "epoched": mne.read_epochs_fieldtrip(fname, info) - elif type == "raw": + elif type_ == "raw": mne.io.read_raw_fieldtrip(fname, info) diff --git a/mne/preprocessing/nirs/_tddr.py b/mne/preprocessing/nirs/_tddr.py index 59c2ec926d9..a7d0af9a305 100644 --- a/mne/preprocessing/nirs/_tddr.py +++ b/mne/preprocessing/nirs/_tddr.py @@ -111,7 +111,6 @@ def _TDDR(signal, sample_rate): tune = 4.685 D = np.sqrt(np.finfo(signal.dtype).eps) mu = np.inf - iter = 0 # Step 1. Compute temporal derivative of the signal deriv = np.diff(signal_low) @@ -120,8 +119,7 @@ def _TDDR(signal, sample_rate): w = np.ones(deriv.shape) # Step 3. Iterative estimation of robust weights - while iter < 50: - iter = iter + 1 + for _ in range(50): mu0 = mu # Step 3a. Estimate weighted mean diff --git a/mne/preprocessing/ssp.py b/mne/preprocessing/ssp.py index 985a30a6e9d..271f9195416 100644 --- a/mne/preprocessing/ssp.py +++ b/mne/preprocessing/ssp.py @@ -13,7 +13,7 @@ from .._fiff.reference import make_eeg_average_ref_proj from ..epochs import Epochs from ..proj import compute_proj_epochs, compute_proj_evoked -from ..utils import logger, verbose, warn +from ..utils import _validate_type, logger, verbose, warn from .ecg import find_ecg_events from .eog import find_eog_events @@ -112,7 +112,10 @@ def _compute_exg_proj( my_info["bads"] += bads # Handler rejection parameters + _validate_type(reject, (None, dict), "reject") + _validate_type(flat, (None, dict), "flat") if reject is not None: # make sure they didn't pass None + reject = reject.copy() # must make a copy or we modify default! if ( len( pick_types( @@ -170,6 +173,7 @@ def _compute_exg_proj( ): _safe_del_key(reject, "eog") if flat is not None: # make sure they didn't pass None + flat = flat.copy() if ( len( pick_types( @@ -300,9 +304,9 @@ def compute_proj_ecg( filter_length="10s", n_jobs=None, ch_name=None, - reject=dict(grad=2000e-13, mag=3000e-15, eeg=50e-6, eog=250e-6), + reject=dict(grad=2000e-13, mag=3000e-15, eeg=50e-6, eog=250e-6), # noqa: B006 flat=None, - bads=[], + bads=(), avg_ref=False, no_proj=False, event_id=999, @@ -461,9 +465,9 @@ def compute_proj_eog( average=True, filter_length="10s", n_jobs=None, - reject=dict(grad=2000e-13, mag=3000e-15, eeg=500e-6, eog=np.inf), + reject=dict(grad=2000e-13, mag=3000e-15, eeg=500e-6, eog=np.inf), # noqa: B006 flat=None, - bads=[], + bads=(), avg_ref=False, no_proj=False, event_id=998, diff --git a/mne/preprocessing/tests/test_ssp.py b/mne/preprocessing/tests/test_ssp.py index 359a844686c..b7565a6c5ce 100644 --- a/mne/preprocessing/tests/test_ssp.py +++ b/mne/preprocessing/tests/test_ssp.py @@ -69,6 +69,9 @@ def test_compute_proj_ecg(short_raw, average): # XXX: better tests # without setting a bad channel, this should throw a warning + # (first with a call that makes sure we copy the mutable default "reject") + with pytest.warns(RuntimeWarning, match="longer than the signal"): + compute_proj_ecg(raw.copy().pick("mag"), l_freq=None, h_freq=None) with pytest.warns(RuntimeWarning, match="No good epochs found"): projs, events, drop_log = compute_proj_ecg( raw, diff --git a/mne/report/report.py b/mne/report/report.py index 6b83642ec8f..34acb8860e6 100644 --- a/mne/report/report.py +++ b/mne/report/report.py @@ -2998,7 +2998,7 @@ def __enter__(self): """Do nothing when entering the context block.""" return self - def __exit__(self, type, value, traceback): + def __exit__(self, exception_type, value, traceback): """Save the report when leaving the context block.""" if self.fname is not None: self.save(self.fname, open_browser=False, overwrite=True) diff --git a/mne/source_estimate.py b/mne/source_estimate.py index 35e14e2e769..66897bcaedc 100644 --- a/mne/source_estimate.py +++ b/mne/source_estimate.py @@ -2476,7 +2476,7 @@ def save_as_volume( src, dest="mri", mri_resolution=False, - format="nifti1", + format="nifti1", # noqa: A002 *, overwrite=False, verbose=None, @@ -2525,7 +2525,13 @@ def save_as_volume( ) nib.save(img, fname) - def as_volume(self, src, dest="mri", mri_resolution=False, format="nifti1"): + def as_volume( + self, + src, + dest="mri", + mri_resolution=False, + format="nifti1", # noqa: A002 + ): """Export volume source estimate as a nifti object. Parameters diff --git a/mne/source_space/_source_space.py b/mne/source_space/_source_space.py index bc17b08e53b..11834cc7631 100644 --- a/mne/source_space/_source_space.py +++ b/mne/source_space/_source_space.py @@ -2047,11 +2047,12 @@ def _make_volume_source_space( volume_labels=None, do_neighbors=True, n_jobs=None, - vol_info={}, + vol_info=None, single_volume=False, ): """Make a source space which covers the volume bounded by surf.""" # Figure out the grid size in the MRI coordinate frame + vol_info = {} if vol_info is None else vol_info if "rr" in surf: mins = np.min(surf["rr"], axis=0) maxs = np.max(surf["rr"], axis=0) diff --git a/mne/time_frequency/csd.py b/mne/time_frequency/csd.py index cea14c9944a..5bca1d03508 100644 --- a/mne/time_frequency/csd.py +++ b/mne/time_frequency/csd.py @@ -35,7 +35,7 @@ @verbose def pick_channels_csd( - csd, include=[], exclude=[], ordered=None, copy=True, *, verbose=None + csd, include=(), exclude=(), ordered=None, copy=True, *, verbose=None ): """Pick channels from cross-spectral density matrix. diff --git a/mne/time_frequency/tfr.py b/mne/time_frequency/tfr.py index 2e9d3102054..3be20ce28fc 100644 --- a/mne/time_frequency/tfr.py +++ b/mne/time_frequency/tfr.py @@ -1468,7 +1468,7 @@ def plot( mask_cmap="Greys", mask_alpha=0.1, combine=None, - exclude=[], + exclude=(), cnorm=None, verbose=None, ): @@ -1667,7 +1667,7 @@ def _plot( exclude=None, copy=True, source_plot_joint=False, - topomap_args=dict(), + topomap_args=None, ch_type=None, cnorm=None, verbose=None, @@ -1676,6 +1676,8 @@ def _plot( See self.plot() for parameters description. """ + _validate_type(topomap_args, (dict, None), "topomap_args") + topomap_args = {} if topomap_args is None else topomap_args import matplotlib.pyplot as plt # channel selection @@ -1821,7 +1823,7 @@ def plot_joint( title=None, yscale="auto", combine="mean", - exclude=[], + exclude=(), topomap_args=None, image_args=None, verbose=None, diff --git a/mne/utils/tests/test_docs.py b/mne/utils/tests/test_docs.py index 0fd13aa25a5..c5ab49d3167 100644 --- a/mne/utils/tests/test_docs.py +++ b/mne/utils/tests/test_docs.py @@ -122,12 +122,12 @@ def m1(): def test_copy_function_doc_to_method_doc(): """Test decorator for re-using function docstring as method docstrings.""" - def f1(object, a, b, c): + def f1(obj, a, b, c): """Docstring for f1. Parameters ---------- - object : object + obj : object Some object. This description also has blank lines in it. @@ -138,7 +138,7 @@ def f1(object, a, b, c): """ pass - def f2(object): + def f2(obj): """Docstring for f2. Parameters @@ -152,7 +152,7 @@ def f2(object): """ pass - def f3(object): + def f3(obj): """Docstring for f3. Parameters @@ -162,11 +162,11 @@ def f3(object): """ pass - def f4(object): + def f4(obj): """Docstring for f4.""" pass - def f5(object): # noqa: D410, D411, D414 + def f5(obj): # noqa: D410, D411, D414 """Docstring for f5. Parameters diff --git a/mne/utils/tests/test_logging.py b/mne/utils/tests/test_logging.py index 8a19d76a089..02a5a7363d0 100644 --- a/mne/utils/tests/test_logging.py +++ b/mne/utils/tests/test_logging.py @@ -73,7 +73,7 @@ def test_how_to_deal_with_warnings(): assert len(w) == 1 -def clean_lines(lines=[]): +def clean_lines(lines=()): """Scrub filenames for checking logging output (in test_logging).""" return [line if "Reading " not in line else "Reading test file" for line in lines] diff --git a/mne/viz/backends/_abstract.py b/mne/viz/backends/_abstract.py index b28468ebc77..c31023401ed 100644 --- a/mne/viz/backends/_abstract.py +++ b/mne/viz/backends/_abstract.py @@ -1136,7 +1136,7 @@ def _dock_add_file_button( desc, func, *, - filter=None, + filter_=None, initial_directory=None, save=False, is_directory=False, @@ -1209,7 +1209,7 @@ def _dialog_create( callback, *, icon="Warning", - buttons=[], + buttons=(), modal=True, window=None, ): diff --git a/mne/viz/backends/_notebook.py b/mne/viz/backends/_notebook.py index 6a9e5a6cf8f..4601ef1fc6a 100644 --- a/mne/viz/backends/_notebook.py +++ b/mne/viz/backends/_notebook.py @@ -976,7 +976,7 @@ def _dialog_create( callback, *, icon="Warning", - buttons=[], + buttons=(), modal=True, window=None, ): @@ -1202,7 +1202,7 @@ def _dock_add_file_button( desc, func, *, - filter=None, + filter_=None, initial_directory=None, save=False, is_directory=False, diff --git a/mne/viz/backends/_qt.py b/mne/viz/backends/_qt.py index 3f7f28abc1b..35cdc4de502 100644 --- a/mne/viz/backends/_qt.py +++ b/mne/viz/backends/_qt.py @@ -930,7 +930,7 @@ def _dialog_create( callback, *, icon="Warning", - buttons=[], + buttons=(), modal=True, window=None, ): @@ -1205,7 +1205,7 @@ def _dock_add_file_button( desc, func, *, - filter=None, + filter_=None, initial_directory=None, save=False, is_directory=False, @@ -1226,11 +1226,11 @@ def callback(): ) elif save: name = QFileDialog.getSaveFileName( - parent=self._window, directory=initial_directory, filter=filter + parent=self._window, directory=initial_directory, filter=filter_ ) else: name = QFileDialog.getOpenFileName( - parent=self._window, directory=initial_directory, filter=filter + parent=self._window, directory=initial_directory, filter=filter_ ) name = name[0] if isinstance(name, tuple) else name # handle the cancel button diff --git a/mne/viz/backends/renderer.py b/mne/viz/backends/renderer.py index 2e2ab1e7333..faa209454e1 100644 --- a/mne/viz/backends/renderer.py +++ b/mne/viz/backends/renderer.py @@ -391,7 +391,7 @@ def _enable_time_interaction( current_time_func, times, init_playback_speed=0.01, - playback_speed_range=[0.01, 0.1], + playback_speed_range=(0.01, 0.1), ): from ..ui_events import ( PlaybackSpeed, diff --git a/mne/viz/circle.py b/mne/viz/circle.py index 7f9d16ecc54..5a3406a7c1b 100644 --- a/mne/viz/circle.py +++ b/mne/viz/circle.py @@ -97,7 +97,13 @@ def circular_layout( def _plot_connectivity_circle_onpick( - event, fig=None, ax=None, indices=None, n_nodes=0, node_angles=None, ylim=[9, 10] + event, + fig=None, + ax=None, + indices=None, + n_nodes=0, + node_angles=None, + ylim=(9, 10), ): """Isolate connections around a single node when user left clicks a node. diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py index 20bdd655a93..96976532767 100644 --- a/mne/viz/evoked.py +++ b/mne/viz/evoked.py @@ -390,9 +390,9 @@ def _plot_evoked( ax.set_xlabel("") ims = [ax.images[0] for ax in axes.values()] clims = np.array([im.get_clim() for im in ims]) - min, max = clims.min(), clims.max() + min_, max_ = clims.min(), clims.max() for im in ims: - im.set_clim(min, max) + im.set_clim(min_, max_) figs = [ax.get_figure() for ax in axes.values()] if len(set(figs)) == 1: return figs[0] @@ -1171,7 +1171,7 @@ def plot_evoked_topo( scalings=None, title=None, proj=False, - vline=[0.0], + vline=(0.0,), fig_background=None, merge_grads=False, legend=True, diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 489f4cb62d8..a531bb7e866 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -183,9 +183,9 @@ def _prepare_topomap_plot(inst, ch_type, sphere=None): # Modify the nirs channel names to indicate they are to be merged # New names will have the form S1_D1xS2_D2 # More than two channels can overlap and be merged - for set in overlapping_channels: - idx = ch_names.index(set[0][:-4]) - new_name = "x".join(s[:-4] for s in set) + for set_ in overlapping_channels: + idx = ch_names.index(set_[0][:-4]) + new_name = "x".join(s[:-4] for s in set_) ch_names[idx] = new_name pos = np.array(pos)[:, :2] # 2D plot, otherwise interpolation bugs @@ -306,12 +306,12 @@ def _add_colorbar( cmap, *, title=None, - format=None, + format_=None, kind=None, ch_type=None, ): """Add a colorbar to an axis.""" - cbar = ax.figure.colorbar(im, format=format, shrink=0.6) + cbar = ax.figure.colorbar(im, format=format_, shrink=0.6) if cmap is not None and cmap[1]: ax.CB = DraggableColorbar(cbar, im, kind, ch_type) cax = cbar.ax @@ -597,7 +597,7 @@ def _plot_projs_topomap( im, cmap, title=units, - format=cbar_fmt, + format_=cbar_fmt, kind="projs_topomap", ch_type=_ch_type, ) @@ -1470,7 +1470,7 @@ def _plot_ica_topomap( im, cmap, title="AU", - format="%3.2f", + format_="%3.2f", kind="ica_topomap", ch_type=ch_type, ) @@ -1709,7 +1709,7 @@ def plot_ica_components( im, cmap, title="AU", - format=cbar_fmt, + format_=cbar_fmt, kind="ica_comp_topomap", ch_type=ch_type, ) @@ -1989,7 +1989,7 @@ def plot_tfr_topomap( im, cmap, title=units, - format=cbar_fmt, + format_=cbar_fmt, kind="tfr_topomap", ch_type=ch_type, ) @@ -2561,7 +2561,7 @@ def _plot_topomap_multi_cbar( ) if colorbar: - cbar, cax = _add_colorbar(ax, im, cmap, title=None, format=cbar_fmt) + cbar, cax = _add_colorbar(ax, im, cmap, title=None, format_=cbar_fmt) cbar.set_ticks(_vlim) if unit is not None: cbar.ax.set_ylabel(unit, fontsize=8) diff --git a/mne/viz/utils.py b/mne/viz/utils.py index 6df8b210c00..eeaf3d1098e 100644 --- a/mne/viz/utils.py +++ b/mne/viz/utils.py @@ -243,12 +243,12 @@ def _validate_if_list_of_axes(axes, obligatory_len=None, name="axes"): ) -def mne_analyze_colormap(limits=[5, 10, 15], format="vtk"): +def mne_analyze_colormap(limits=(5, 10, 15), format="vtk"): # noqa: A002 """Return a colormap similar to that used by mne_analyze. Parameters ---------- - limits : list (or array) of length 3 or 6 + limits : array-like of length 3 or 6 Bounds for the colormap, which will be mirrored across zero if length 3, or completely specified (and potentially asymmetric) if length 6. format : str diff --git a/pyproject.toml b/pyproject.toml index abb2e1b3f1b..ba292f3ac6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -204,7 +204,7 @@ builtin = "clear,rare,informal,names,usage" skip = "doc/references.bib" [tool.ruff] -select = ["E", "F", "W", "D", "I", "UP"] +select = ["A", "B006", "D", "E", "F", "I", "W", "UP"] exclude = ["__init__.py", "constants.py", "resources.py"] ignore = [ "D100", # Missing docstring in public module