Skip to content

Commit 63a8ce2

Browse files
authored
MRG: Upgrade to Python3 syntax using pyupgrade (#5917)
* ENH: Upgrade to Python3 syntax using pyupgrade * FIX: Flake
1 parent 62acff0 commit 63a8ce2

59 files changed

Lines changed: 191 additions & 199 deletions

Some content is hidden

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

mne/bem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def make_sphere_model(r0=(0., 0., 0.04), head_radius=0.09, info=None,
809809
'eeg': FIFF.FIFFV_POINT_EEG,
810810
'extra': FIFF.FIFFV_POINT_EXTRA,
811811
}
812-
_dig_kind_rev = dict((val, key) for key, val in _dig_kind_dict.items())
812+
_dig_kind_rev = {val: key for key, val in _dig_kind_dict.items()}
813813
_dig_kind_ints = tuple(_dig_kind_dict.values())
814814

815815

@@ -1454,7 +1454,7 @@ def _bem_find_surface(bem, id_):
14541454

14551455
def _bem_explain_surface(id_):
14561456
"""Return a string corresponding to the given surface ID."""
1457-
_rev_dict = dict((val, key) for key, val in _surf_dict.items())
1457+
_rev_dict = {val: key for key, val in _surf_dict.items()}
14581458
return _rev_dict[id_]
14591459

14601460

mne/channels/channels.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ def _ch_neighbor_connectivity(ch_names, neighbors):
11271127
if len(ch_names) != len(neighbors):
11281128
raise ValueError('`ch_names` and `neighbors` must '
11291129
'have the same length')
1130-
set_neighbors = set([c for d in neighbors for c in d])
1130+
set_neighbors = {c for d in neighbors for c in d}
11311131
rest = set_neighbors - set(ch_names)
11321132
if len(rest) > 0:
11331133
raise ValueError('Some of your neighbors are not present in the '
@@ -1338,8 +1338,8 @@ def _get_ch_info(info):
13381338
"""Get channel info for inferring acquisition device."""
13391339
chs = info['chs']
13401340
# Only take first 16 bits, as higher bits store CTF comp order
1341-
coil_types = set([ch['coil_type'] & 0xFFFF for ch in chs])
1342-
channel_types = set([ch['kind'] for ch in chs])
1341+
coil_types = {ch['coil_type'] & 0xFFFF for ch in chs}
1342+
channel_types = {ch['kind'] for ch in chs}
13431343

13441344
has_vv_mag = any(k in coil_types for k in
13451345
[FIFF.FIFFV_COIL_VV_MAG_T1, FIFF.FIFFV_COIL_VV_MAG_T2,

mne/channels/interpolation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _do_interp_dots(inst, interpolation, goods_idx, bads_idx):
101101
inst._data[:, bads_idx, :] = einsum(
102102
'ij,xjy->xiy', interpolation, inst._data[:, goods_idx, :])
103103
else:
104-
raise ValueError('Inputs of type {0} are not supported'
104+
raise ValueError('Inputs of type {} are not supported'
105105
.format(type(inst)))
106106

107107

@@ -146,12 +146,12 @@ def _interpolate_bads_eeg(inst, verbose=None):
146146
warn('Your spherical fit is poor, interpolation results are '
147147
'likely to be inaccurate.')
148148

149-
logger.info('Computing interpolation matrix from {0} sensor '
149+
logger.info('Computing interpolation matrix from {} sensor '
150150
'positions'.format(len(pos_good)))
151151

152152
interpolation = _make_interpolation_matrix(pos_good, pos_bad)
153153

154-
logger.info('Interpolating {0} sensors'.format(len(pos_bad)))
154+
logger.info('Interpolating {} sensors'.format(len(pos_bad)))
155155
_do_interp_dots(inst, interpolation, goods_idx, bads_idx)
156156

157157

mne/channels/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ def generate_2d_layout(xy, w=.07, h=.05, pad=.02, ch_names=None,
957957
if ch_indices is None:
958958
ch_indices = np.arange(xy.shape[0])
959959
if ch_names is None:
960-
ch_names = ['{0}'.format(i) for i in ch_indices]
960+
ch_names = ['{}'.format(i) for i in ch_indices]
961961

962962
if len(ch_names) != len(ch_indices):
963963
raise ValueError('# channel names and indices must be equal')

mne/channels/montage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def read_montage(kind, ch_names=None, path=None, unit='m', transform=False):
263263
break
264264
pos.append(list(map(float, line.split())))
265265
for line in fid:
266-
if not line or not set(line) - set([' ']):
266+
if not line or not set(line) - {' '}:
267267
break
268268
ch_names_.append(line.strip(' ').strip('\n'))
269269
pos = np.array(pos) * scale_factor

mne/coreg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def fit_matched_points(src_pts, tgt_pts, rotate=True, translate=True,
343343
tgt_pts = np.atleast_2d(tgt_pts)
344344
if src_pts.shape != tgt_pts.shape:
345345
raise ValueError("src_pts and tgt_pts must have same shape (got "
346-
"{0}, {1})".format(src_pts.shape, tgt_pts.shape))
346+
"{}, {})".format(src_pts.shape, tgt_pts.shape))
347347
if weights is not None:
348348
weights = np.array(weights, float)
349349
if weights.ndim != 1 or weights.size not in (src_pts.shape[0], 1):

mne/cov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ def _unpack_epochs(epochs):
912912
out = covs
913913
else:
914914
out = covs[0]
915-
logger.info('selecting best estimator: {0}'.format(out['method']))
915+
logger.info('selecting best estimator: {}'.format(out['method']))
916916
else:
917917
out = covs[0]
918918
logger.info('[done]')

mne/datasets/sleep_physionet/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _update_sleep_temazepam_records(fname=TEMAZEPAM_SLEEP_RECORDS):
113113
data = data.rename(columns={('Subject - age - sex', 'Age'): 'age',
114114
('Subject - age - sex', 'M1/F2'): 'sex',
115115
'level_3': 'drug'})
116-
data['id'] = ['ST7{0:02d}{1:1d}'.format(s, n)
116+
data['id'] = ['ST7{:02d}{:1d}'.format(s, n)
117117
for s, n in zip(data.subject, data['night nr'])]
118118

119119
data = pd.merge(sha1_df, data, how='outer', on='id')
@@ -172,7 +172,7 @@ def _update_sleep_age_records(fname=AGE_SLEEP_RECORDS):
172172
data['sex'] = (data.sex.astype('category')
173173
.cat.rename_categories({1: 'female', 2: 'male'}))
174174

175-
data['id'] = ['SC4{0:02d}{1:1d}'.format(s, n)
175+
data['id'] = ['SC4{:02d}{:1d}'.format(s, n)
176176
for s, n in zip(data.subject, data.night)]
177177

178178
data = data.set_index('id').join(sha1_df.set_index('id')).dropna()

mne/decoding/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ def _fit_and_score(estimator, X, y, scorer, train, test, verbose,
471471

472472
# Adjust length of sample weights
473473
fit_params = fit_params if fit_params is not None else {}
474-
fit_params = dict([(k, _index_param_value(X, v, train))
475-
for k, v in fit_params.items()])
474+
fit_params = {k: _index_param_value(X, v, train)
475+
for k, v in fit_params.items()}
476476

477477
if parameters is not None:
478478
estimator.set_params(**parameters)

mne/dipole.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def _read_dipole_text(fname):
569569
assert len(handled_fields) == len(required_fields) + len(optional_fields)
570570
ignored_fields = sorted(set(fields) -
571571
set(handled_fields) -
572-
set(['end/ms']))
572+
{'end/ms'})
573573
if len(ignored_fields) > 0:
574574
warn('Ignoring extra fields in dipole file: %s' % (ignored_fields,))
575575
if len(fields) != data.shape[1]:

0 commit comments

Comments
 (0)