Skip to content

Commit 1337aa6

Browse files
committed
Replace 'is' by == to check content
1 parent 860f14b commit 1337aa6

File tree

10 files changed

+49
-49
lines changed

10 files changed

+49
-49
lines changed

frites/core/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def get_core_mi_fun(mi_method):
3636
Dictionary of methods
3737
"""
3838
assert mi_method in ['gc', 'bin']
39-
if mi_method is 'gc':
39+
if mi_method == 'gc':
4040
from .mi_gc_ephy import (mi_gc_ephy_cc, mi_gc_ephy_cd, mi_gc_ephy_ccd,
4141
mi_gc_ephy_conn_cc)
4242
mi_fun = dict(cc=mi_gc_ephy_cc, cd=mi_gc_ephy_cd, ccd=mi_gc_ephy_ccd,
4343
cc_conn=mi_gc_ephy_conn_cc)
44-
elif mi_method is 'bin':
44+
elif mi_method == 'bin':
4545
from .mi_bin_ephy import (mi_bin_ephy_cc, mi_bin_ephy_cd,
4646
mi_bin_ephy_ccd, mi_bin_ephy_conn_cc)
4747
mi_fun = dict(cc=mi_bin_ephy_cc, cd=mi_bin_ephy_cd,

frites/core/tests/test_mi_fun.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_mi_fun(self):
2727
for mi in mi_types:
2828
fun = mi_funs[mi]
2929
for inf in inferences:
30-
y_c = z if mi is 'cd' else y
30+
y_c = z if mi == 'cd' else y
3131
fun(x, y_c, z, suj, inf)
3232
# test mi conn
3333
x_2 = rnd.rand(n_times, 1, n_epochs)
@@ -54,9 +54,9 @@ def test_permute_mi_trials(self):
5454
assert len(y_p) == n_perm
5555

5656
# rfx testing
57-
if inf is 'ffx':
57+
if inf == 'ffx':
5858
assert any([k[0:3].max() > 2 for k in y_p])
59-
elif inf is 'rfx':
59+
elif inf == 'rfx':
6060
for k in y_p:
6161
assert (k[0:3].min() == 0) and (k[0:3].max() == 2)
6262
assert (k[3::].min() == 3) and (k[3::].max() == 5)

frites/io/io_conversion.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ def convert_spatiotemporal_outputs(arr, times, roi, astype='array'):
3232
# output conversion
3333
force_np = not is_pandas_installed() and not is_xarray_installed()
3434
astype = 'array' if force_np else astype
35-
if astype is 'array': # numpy
35+
if astype == 'array': # numpy
3636
return arr
37-
elif astype is 'dataframe': # pandas
37+
elif astype == 'dataframe': # pandas
3838
is_pandas_installed(raise_error=True)
3939
import pandas as pd
4040
return pd.DataFrame(arr, index=times, columns=roi)
41-
elif astype is 'dataarray': # xarray
41+
elif astype == 'dataarray': # xarray
4242
is_xarray_installed(raise_error=True)
4343
from xarray import DataArray
4444
return DataArray(arr, dims=('times', 'roi'), coords=(times, roi))
@@ -105,22 +105,22 @@ def convert_dfc_outputs(arr, times, roi, sources, targets, astype='2d_array',
105105
force_np = not is_pandas_installed() and not is_xarray_installed()
106106
astype = '2d_array' if force_np else astype
107107

108-
if astype is '2d_array':
108+
if astype == '2d_array':
109109
return arr
110-
elif astype is '3d_array':
110+
elif astype == '3d_array':
111111
out = empty_fcn((len(roi), len(roi), n_times))
112112
out[sources, targets, :] = arr.T
113113
return out
114-
elif astype is '2d_dataframe':
114+
elif astype == '2d_dataframe':
115115
import pandas as pd
116116
columns = [(s, t) for s, t in zip(s_roi, t_roi)]
117117
return pd.DataFrame(arr, index=times, columns=columns)
118-
elif astype is '3d_dataframe':
118+
elif astype == '3d_dataframe':
119119
import pandas as pd
120120
idx = pd.MultiIndex.from_arrays([s_roi, t_roi],
121121
names=['source', 'target'])
122122
return pd.DataFrame(arr, index=times, columns=idx)
123-
elif astype is 'dataarray':
123+
elif astype == 'dataarray':
124124
from xarray import DataArray
125125
out = empty_fcn((len(roi), len(roi), n_times))
126126
out[sources, targets, :] = arr.T

frites/simulations/sim_ar.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def fit(self, ar_type='hga', sf=200, n_times=300, n_epochs=100, dt=50,
7676
kw_noise = dict(size=(n_epochs_tot, n_times), loc=0,
7777
random_state=random_state)
7878

79-
if ar_type is 'hga':
79+
if ar_type == 'hga':
8080
self._lab = 'Evoked HGA'
81-
elif ar_type is 'osc_20':
81+
elif ar_type == 'osc_20':
8282
self._lab = '20Hz oscillations'
8383
elif ar_type in ['osc_40', 'osc_40_3']:
8484
self._lab = '40Hz oscillations'
@@ -163,7 +163,7 @@ def fit(self, ar_type='hga', sf=200, n_times=300, n_epochs=100, dt=50,
163163
x[:, _sl_a12] @ a12)
164164
# concatenate everything
165165
dat, roi = np.stack((x, y), axis=1), ['x', 'y']
166-
elif ar_type is 'osc_40_3':
166+
elif ar_type == 'osc_40_3':
167167
n1, n2, n3 = self._generate_noise(var=[.05] * 3, **kw_noise)
168168
c2 = self._n_std_gain(c, n2, n_std)
169169
c3 = self._n_std_gain(c, n3, n_std)
@@ -176,7 +176,7 @@ def fit(self, ar_type='hga', sf=200, n_times=300, n_epochs=100, dt=50,
176176
z[:, t] = n3[:, t] + .35 * z[:, t - 1] - .5 * z[:, t - 2] + (
177177
c3[:, t] * (.5 * x[:, t - 1]))
178178
dat, roi = np.stack((x, y, z), axis=1), ['x', 'y', 'z']
179-
elif ar_type is 'ding_2':
179+
elif ar_type == 'ding_2':
180180
n1, n2 = self._generate_noise(var=[1., .7], **kw_noise)
181181
c2 = self._n_std_gain(c, n2, n_std)
182182

@@ -194,10 +194,10 @@ def fit(self, ar_type='hga', sf=200, n_times=300, n_epochs=100, dt=50,
194194

195195
x, y, z = n1, n2, n3
196196
for t in range(2, n_times):
197-
if ar_type is 'ding_3_indirect':
197+
if ar_type == 'ding_3_indirect':
198198
x[:, t] = .8 * x[:, t - 1] - .5 * x[:, t - 2] + c1[
199199
:, t] * (.4 * z[:, t - 1]) + n1[:, t]
200-
elif ar_type is 'ding_3_direct':
200+
elif ar_type == 'ding_3_direct':
201201
x[:, t] = .8 * x[:, t - 1] - .5 * x[:, t - 2] + c1[
202202
:, t] * (.4 * z[:, t - 1] + .2 * y[:, t - 2]) + n1[
203203
:, t]
@@ -206,7 +206,7 @@ def fit(self, ar_type='hga', sf=200, n_times=300, n_epochs=100, dt=50,
206206
.5 * y[:, t - 1]) + n3[:, t]
207207
dat, roi = np.stack((x, y, z), axis=1), ['x', 'y', 'z']
208208
ar_type = 'ding_3'
209-
elif ar_type is 'ding_5':
209+
elif ar_type == 'ding_5':
210210
n1, n2, n3, n4, n5 = self._generate_noise(var=[.6, .5, .3, .3, .6],
211211
**kw_noise)
212212
c2 = self._n_std_gain(c, n2, n_std)
@@ -411,20 +411,20 @@ def plot_model(self):
411411
lab = self._lab
412412
edge_labels = {('X', 'Y'): lab + f"\n(n_stim={self._n_stim}, "
413413
f"n_std={self._n_std})"}
414-
elif self._ar_type is 'osc_40_3':
414+
elif self._ar_type == 'osc_40_3':
415415
G.add_edges_from([('X', 'Y')], weight=1)
416416
G.add_edges_from([('X', 'Z')], weight=1)
417417
lab = self._lab
418418
edge_labels = {(u, v): rf"{u}$\rightarrow${v}={d['weight']}" for
419419
u, v, d in G.edges(data=True)}
420420
elif self._ar_type in ['ding_2', 'ding_3', 'ding_5']:
421-
if self._ar_type is 'ding_2':
421+
if self._ar_type == 'ding_2':
422422
G.add_edges_from([('X', 'Y')], weight=1)
423-
elif self._ar_type is 'ding_3':
423+
elif self._ar_type == 'ding_3':
424424
G.add_edges_from([('Y', 'X')], weight=5)
425425
G.add_edges_from([('Y', 'Z')], weight=6)
426426
G.add_edges_from([('Z', 'X')], weight=4)
427-
elif self._ar_type is 'ding_5':
427+
elif self._ar_type == 'ding_5':
428428
G.add_edges_from([('X1', 'X2'), ('X1', 'X3'), ('X1', 'X4')],
429429
weight=5)
430430
G.add_edges_from([('X4', 'X5')], weight=2)
@@ -433,9 +433,9 @@ def plot_model(self):
433433
edge_labels = {(u, v): rf"{u}$\rightarrow${v}={d['weight']}" for
434434
u, v, d in G.edges(data=True)}
435435
# fix ding_5 for bidirectional connectivity between 4 <-> 5
436-
if self._ar_type is 'ding_3':
436+
if self._ar_type == 'ding_3':
437437
edge_labels[('Y', 'X')] = "indirect\n(mediated by Z)"
438-
elif self._ar_type is 'ding_5':
438+
elif self._ar_type == 'ding_5':
439439
edge_labels[('X5', 'X4')] = (r"X4$\rightarrow$X5=2" + "\n" +
440440
r'X5$\rightarrow$X4=1')
441441

frites/stats/stats_mcp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ def testwise_correction_mcp(x, x_p, tail=1, mcp='maxstat'):
6363

6464
# -------------------------------------------------------------------------
6565
# mcp correction
66-
if mcp is 'maxstat':
66+
if mcp == 'maxstat':
6767
x_p_sh = tuple([n_perm] + [1] * (x.ndim - 1))
6868
# maximum over all dimensions except the perm one
6969
x_p = x_p.reshape(n_perm, -1).max(1).reshape(*x_p_sh)
7070
pv = (x <= x_p).sum(0) / n_perm
7171
pv = np.clip(pv, 1. / n_perm, 1.)
7272
else:
7373
pv = (x <= x_p).sum(0) / n_perm
74-
if mcp is 'fdr':
74+
if mcp == 'fdr':
7575
pv = fdr_correction(pv, .05)[1]
76-
if mcp is 'bonferroni':
76+
if mcp == 'bonferroni':
7777
pv = bonferroni_correction(pv, .05)[1]
7878
pv = np.clip(pv, 0., 1.)
7979

frites/workflow/tests/test_wf_stats_ephy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def test_fit(self):
5454

5555
for inf, mcp in prod:
5656
# data selection
57-
if inf is 'ffx': x, x_p = effect_ffx, perms_ffx # noqa
58-
elif inf is 'rfx': x, x_p = effect_rfx, perms_rfx # noqa
57+
if inf == 'ffx': x, x_p = effect_ffx, perms_ffx # noqa
58+
elif inf == 'rfx': x, x_p = effect_rfx, perms_rfx # noqa
5959
# threshold definition
60-
if mcp is 'cluster':
60+
if mcp == 'cluster':
6161
cluster_th = [None, 'tfce']
6262
else:
6363
cluster_th = [None]
@@ -76,4 +76,4 @@ def test_fit(self):
7676
pv, tv = wf.fit(x, x_p, **kw)
7777
self._testing(gt_bot.T, pv, kw)
7878

79-
assert wf.cluster_th is 'tfce'
79+
assert wf.cluster_th == 'tfce'

frites/workflow/wf_conn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, inference='rfx', mi_method='gc', kernel=None,
6161
self._inference = inference
6262
self._mi_method = mi_method
6363
self._need_copnorm = mi_method == 'gc'
64-
self._gcrn = inference is 'rfx'
64+
self._gcrn = inference == 'rfx'
6565
self._kernel = kernel
6666
set_log_level(verbose)
6767
self.clean()
@@ -213,7 +213,7 @@ def fit(self, dataset, mcp='cluster', n_perm=1000, cluster_th=None,
213213
if mcp in ['noperm', None]:
214214
n_perm = 0
215215
# infer the number of bins if needed
216-
if (self._mi_method is 'bin') and not isinstance(n_bins, int):
216+
if (self._mi_method == 'bin') and not isinstance(n_bins, int):
217217
n_bins = 4
218218
logger.info(f" Use an automatic number of bins of {n_bins}")
219219
self._n_bins = n_bins
@@ -253,9 +253,9 @@ def fit(self, dataset, mcp='cluster', n_perm=1000, cluster_th=None,
253253
if isinstance(tvalues, np.ndarray):
254254
self._tvalues = convert_dfc_outputs(tvalues, *args)
255255
pvalues = convert_dfc_outputs(pvalues, is_pvalue=True, *args)
256-
if self._inference is 'rfx':
256+
if self._inference == 'rfx':
257257
mi = np.stack([k.mean(axis=0) for k in mi]).T # mean mi
258-
elif self._inference is 'ffx':
258+
elif self._inference == 'ffx':
259259
mi = np.concatenate(mi, axis=0).T # mi
260260
mi = convert_dfc_outputs(mi, *args)
261261
# converting outputs

frites/workflow/wf_fit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _node_compute_fit(self, dataset, n_perm, n_jobs, max_delay, net,
101101
f"n_pairs={len(all_s)})")
102102
# get the unique subjects across roi (depends on inference type)
103103
inference = self._inference
104-
if inference is 'ffx':
104+
if inference == 'ffx':
105105
sujr = [np.array([0])] * n_roi
106106
else:
107107
sujr = dataset.suj_roi_u
@@ -254,9 +254,9 @@ def fit(self, dataset, max_delay=0.3, net=False, mcp='cluster',
254254
if isinstance(tvalues, np.ndarray):
255255
self._tvalues = convert_dfc_outputs(tvalues, *args)
256256
pvalues = convert_dfc_outputs(pvalues, is_pvalue=True, *args)
257-
if inference is 'ffx':
257+
if inference == 'ffx':
258258
fit = np.concatenate(self._fit_roi, axis=0).T # mi
259-
elif inference is 'rfx':
259+
elif inference == 'rfx':
260260
fit = np.stack(self._fit_m, axis=1) # mean mi
261261
fit = convert_dfc_outputs(fit, *args)
262262
# adding attributes

frites/workflow/wf_mi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, mi_type='cc', inference='rfx', mi_method='gc',
7272
self._inference = inference
7373
self._mi_method = mi_method
7474
self._need_copnorm = mi_method == 'gc'
75-
self._gcrn = inference is 'rfx'
75+
self._gcrn = inference == 'rfx'
7676
self._kernel = kernel
7777
set_log_level(verbose)
7878
self.clean()
@@ -230,7 +230,7 @@ def fit(self, dataset, mcp='cluster', n_perm=1000, cluster_th=None,
230230
if mcp in ['noperm', None]:
231231
n_perm = 0
232232
# infer the number of bins if needed
233-
if (self._mi_method is 'bin') and not isinstance(n_bins, int):
233+
if (self._mi_method == 'bin') and not isinstance(n_bins, int):
234234
n_bins = 4
235235
logger.info(f" Use an automatic number of bins of {n_bins}")
236236
self._n_bins = n_bins
@@ -253,7 +253,7 @@ def fit(self, dataset, mcp='cluster', n_perm=1000, cluster_th=None,
253253
permuted mi but then, the statistics at the local representation mcp
254254
are discarded in favor of statistics on the information transfer
255255
"""
256-
if mcp is 'nostat':
256+
if mcp == 'nostat':
257257
logger.debug("Permutations computed. Stop there")
258258
return None
259259

@@ -288,7 +288,7 @@ def fit(self, dataset, mcp='cluster', n_perm=1000, cluster_th=None,
288288
if isinstance(tvalues, np.ndarray):
289289
self._tvalues = self._xr_conversion(tvalues, 'tvalues')
290290
# mean mi across subjects
291-
if self._inference is 'rfx':
291+
if self._inference == 'rfx':
292292
logger.info(" Mean mi across subjects")
293293
mi = [k.mean(axis=0, keepdims=True) for k in mi]
294294
mi = np.moveaxis(np.concatenate(mi, axis=0), 0, -1)

frites/workflow/wf_stats_ephy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ def fit(self, effect, perms, inference='rfx', mcp='cluster', tail=1,
110110
# FFX / RFX
111111
# ---------------------------------------------------------------------
112112
nb_suj_roi = [k.shape[0] for k in effect]
113-
if inference is 'ffx':
113+
if inference == 'ffx':
114114
# check that the number of subjects is 1
115115
ffx_suj = np.max(nb_suj_roi) == 1
116116
assert ffx_suj, "For FFX, `n_subjects` should be 1"
117117
es, es_p = effect, perms
118118
logger.info(" Fixed-effect inference (FFX)")
119119
# es = (n_roi, n_times); es_p = (n_perm, n_roi, n_times)
120120
es, es_p = np.concatenate(es, axis=0), np.concatenate(es_p, axis=1)
121-
elif inference is 'rfx':
121+
elif inference == 'rfx':
122122
if ttested:
123123
es = np.concatenate(effect, axis=0)
124124
es_p = np.concatenate(perms, axis=1)
@@ -136,11 +136,11 @@ def fit(self, effect, perms, inference='rfx', mcp='cluster', tail=1,
136136
# ---------------------------------------------------------------------
137137
# cluster forming threshold
138138
# ---------------------------------------------------------------------
139-
if mcp is 'cluster':
139+
if mcp == 'cluster':
140140
if isinstance(cluster_th, (int, float)):
141141
th, tfce = cluster_th, None
142142
else:
143-
if (cluster_th is 'tfce'): # TFCE auto
143+
if (cluster_th == 'tfce'): # TFCE auto
144144
tfce = True
145145
elif isinstance(cluster_th, dict): # TFCE manual
146146
tfce = cluster_th
@@ -154,7 +154,7 @@ def fit(self, effect, perms, inference='rfx', mcp='cluster', tail=1,
154154
# ---------------------------------------------------------------------
155155
# test-wise or cluster-based correction for multiple comparisons
156156
# ---------------------------------------------------------------------
157-
if mcp is 'cluster':
157+
if mcp == 'cluster':
158158
logger.info(' Inference at cluster-level')
159159
pvalues = cluster_correction_mcp(es, es_p, th, tail=tail)
160160
else:

0 commit comments

Comments
 (0)