Skip to content

Commit 53b6daf

Browse files
committed
STY: Switch from == to is for type comparrison
Switch to comply with new flake8 rule E721
1 parent 56e9c56 commit 53b6daf

File tree

15 files changed

+47
-43
lines changed

15 files changed

+47
-43
lines changed

statsmodels/base/tests/test_data.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from statsmodels.compat.pandas import assert_series_equal, assert_frame_equal,\
2-
make_dataframe
1+
from statsmodels.compat.pandas import (
2+
assert_series_equal,
3+
assert_frame_equal,
4+
make_dataframe,
5+
)
36

47
import numpy as np
58
from numpy.testing import assert_equal, assert_, assert_raises

statsmodels/distributions/copula/copulas.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class CopulaDistribution:
2424
Parameters
2525
----------
2626
copula : :class:`Copula` instance
27-
An instance of :class:`Copula`, e.g. :class:`GaussianCopula`, :class:`FrankCopula`, etc.
27+
An instance of :class:`Copula`, e.g. :class:`GaussianCopula`,
28+
:class:`FrankCopula`, etc.
2829
marginals : list of distribution instances
2930
Marginal distributions.
3031
copargs : tuple

statsmodels/genmod/generalized_estimating_equations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2405,14 +2405,14 @@ def setup_ordinal(self, endog, exog, groups, time, offset):
24052405

24062406
# exog column names, including intercepts
24072407
xnames = ["I(y>%.1f)" % v for v in endog_cuts]
2408-
if type(self.exog_orig) == pd.DataFrame:
2408+
if type(self.exog_orig) is pd.DataFrame:
24092409
xnames.extend(self.exog_orig.columns)
24102410
else:
24112411
xnames.extend(["x%d" % k for k in range(1, exog.shape[1] + 1)])
24122412
exog_out = pd.DataFrame(exog_out, columns=xnames)
24132413

24142414
# Preserve the endog name if there is one
2415-
if type(self.endog_orig) == pd.Series:
2415+
if type(self.endog_orig) is pd.Series:
24162416
endog_out = pd.Series(endog_out, name=self.endog_orig.name)
24172417

24182418
return endog_out, exog_out, groups_out, time_out, offset_out

statsmodels/regression/mixed_linear_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2948,7 +2948,7 @@ def rlu():
29482948

29492949
data = data[tokens]
29502950
ii = pd.notnull(data).all(1)
2951-
if type(groups) != "str":
2951+
if type(groups) is not str:
29522952
ii &= pd.notnull(groups)
29532953

29542954
return data.loc[ii, :], groups[np.asarray(ii)]

statsmodels/stats/correlation_tools.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def corr_nearest_factor(corr, rank, ctol=1e-6, lam_min=1e-30,
635635

636636
# Zero the diagonal
637637
corr1 = corr.copy()
638-
if type(corr1) == np.ndarray:
638+
if type(corr1) is np.ndarray:
639639
np.fill_diagonal(corr1, 0)
640640
elif sparse.issparse(corr1):
641641
corr1.setdiag(np.zeros(corr1.shape[0]))
@@ -647,7 +647,7 @@ def corr_nearest_factor(corr, rank, ctol=1e-6, lam_min=1e-30,
647647
# The gradient, from lemma 4.1 of BHR.
648648
def grad(X):
649649
gr = np.dot(X, np.dot(X.T, X))
650-
if type(corr1) == np.ndarray:
650+
if type(corr1) is np.ndarray:
651651
gr -= np.dot(corr1, X)
652652
else:
653653
gr -= corr1.dot(X)
@@ -657,7 +657,7 @@ def grad(X):
657657
# The objective function (sum of squared deviations between fitted
658658
# and observed arrays).
659659
def func(X):
660-
if type(corr1) == np.ndarray:
660+
if type(corr1) is np.ndarray:
661661
M = np.dot(X, X.T)
662662
np.fill_diagonal(M, 0)
663663
M -= corr1

statsmodels/tsa/base/tests/test_tsa_indexes.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,13 @@ def test_instantiation_valid():
327327
endog.index = supported_increment_indexes[1][0]
328328

329329
mod = tsa_model.TimeSeriesModel(endog)
330-
assert_equal(type(mod._index) == pd.RangeIndex, True)
331-
assert_equal(mod._index_none, False)
332-
assert_equal(mod._index_dates, False)
333-
assert_equal(mod._index_generated, False)
334-
assert_equal(mod._index_freq, None)
335-
assert_equal(mod.data.dates, None)
336-
assert_equal(mod.data.freq, None)
330+
assert type(mod._index) is pd.RangeIndex
331+
assert not mod._index_none
332+
assert not mod._index_dates
333+
assert not mod._index_generated
334+
assert mod._index_freq is None
335+
assert mod.data.dates is None
336+
assert mod.data.freq is None
337337

338338
# Supported indexes *when a freq is given*, should not raise a warning
339339
with warnings.catch_warnings():
@@ -402,12 +402,12 @@ def test_instantiation_valid():
402402
freq = ix.freq
403403
if not isinstance(freq, str):
404404
freq = freq.freqstr
405-
assert_equal(type(mod._index) == pd.DatetimeIndex, True)
406-
assert_equal(mod._index_none, False)
407-
assert_equal(mod._index_dates, True)
408-
assert_equal(mod._index_generated, False)
405+
assert type(mod._index) is pd.DatetimeIndex
406+
assert not mod._index_none
407+
assert mod._index_dates
408+
assert not mod._index_generated
409409
assert_equal(mod._index.freq, mod._index_freq)
410-
assert_equal(mod.data.dates.equals(mod._index), True)
410+
assert mod.data.dates.equals(mod._index)
411411

412412
# Note: here, we need to hedge the test a little bit because
413413
# inferred frequencies are not always the same as the original

statsmodels/tsa/regime_switching/markov_switching.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ def __getitem__(self, key):
409409
elif _type is tuple:
410410
if not len(key) == 2:
411411
raise IndexError('Invalid index')
412-
if type(key[1]) == str and type(key[0]) == int:
412+
if type(key[1]) is str and type(key[0]) is int:
413413
return self.index_regime_purpose[key[0]][key[1]]
414-
elif type(key[0]) == str and type(key[1]) == int:
414+
elif type(key[0]) is str and type(key[1]) is int:
415415
return self.index_regime_purpose[key[1]][key[0]]
416416
else:
417417
raise IndexError('Invalid index')

statsmodels/tsa/statespace/kalman_filter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ def impulse_responses(self, steps=10, impulse=0, orthogonalized=False,
12671267
steps += 1
12681268

12691269
# Check for what kind of impulse we want
1270-
if type(impulse) == int:
1270+
if type(impulse) is int:
12711271
if impulse >= self.k_posdef or impulse < 0:
12721272
raise ValueError('Invalid value for `impulse`. Must be the'
12731273
' index of one of the state innovations.')

statsmodels/tsa/statespace/mlemodel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,7 @@ def impulse_responses(self, params, steps=1, impulse=0,
22312231

22322232
# Convert endog name to index
22332233
use_pandas = isinstance(self.data, PandasData)
2234-
if type(impulse) == str:
2234+
if type(impulse) is str:
22352235
if not use_pandas:
22362236
raise ValueError('Endog must be pd.DataFrame.')
22372237
impulse = self.endog_names.index(impulse)
@@ -5030,7 +5030,7 @@ def conf_int(self, method='endpoint', alpha=0.05, **kwds):
50305030

50315031
# Attach the endog names
50325032
ynames = self.model.data.ynames
5033-
if not type(ynames) == list:
5033+
if type(ynames) is not list:
50345034
ynames = [ynames]
50355035
names = (['lower {0}'.format(name) for name in ynames] +
50365036
['upper {0}'.format(name) for name in ynames])

statsmodels/tsa/statespace/sarimax.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1015,9 +1015,9 @@ def start_params(self):
10151015
if self.state_regression and self.time_varying_regression:
10161016
# TODO how to set the initial variance parameters?
10171017
params_exog_variance = [1] * self._k_exog
1018-
if (self.state_error and type(params_variance) == list and
1018+
if (self.state_error and type(params_variance) is list and
10191019
len(params_variance) == 0):
1020-
if not (type(params_seasonal_variance) == list and
1020+
if not (type(params_seasonal_variance) is list and
10211021
len(params_seasonal_variance) == 0):
10221022
params_variance = params_seasonal_variance
10231023
elif self._k_exog > 0:

statsmodels/tsa/statespace/tests/test_tools.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def test_cases(self):
393393
# Test that the constrained results correspond to companion matrices
394394
# with eigenvalues less than 1 in modulus
395395
for unconstrained in self.eigval_cases:
396-
if type(unconstrained) == list:
396+
if type(unconstrained) is list:
397397
cov = np.eye(unconstrained[0].shape[0])
398398
else:
399399
cov = np.eye(unconstrained.shape[0])
@@ -446,7 +446,7 @@ class TestStationaryMultivariate:
446446

447447
def test_cases(self):
448448
for constrained in self.constrained_cases:
449-
if type(constrained) == list:
449+
if type(constrained) is list:
450450
cov = np.eye(constrained[0].shape[0])
451451
else:
452452
cov = np.eye(constrained.shape[0])
@@ -455,7 +455,7 @@ def test_cases(self):
455455
assert_allclose(reconstrained, constrained)
456456

457457
for unconstrained in self.unconstrained_cases:
458-
if type(unconstrained) == list:
458+
if type(unconstrained) is list:
459459
cov = np.eye(unconstrained[0].shape[0])
460460
else:
461461
cov = np.eye(unconstrained.shape[0])

statsmodels/tsa/statespace/tools.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ def constrain_stationary_multivariate_python(unconstrained, error_variance,
836836
American Statistical Association
837837
"""
838838

839-
use_list = type(unconstrained) == list
839+
use_list = type(unconstrained) is list
840840
if not use_list:
841841
k_endog, order = unconstrained.shape
842842
order //= k_endog
@@ -872,7 +872,7 @@ def constrain_stationary_multivariate(unconstrained, variance,
872872
transform_variance=False,
873873
prefix=None):
874874

875-
use_list = type(unconstrained) == list
875+
use_list = type(unconstrained) is list
876876
if use_list:
877877
unconstrained = np.concatenate(unconstrained, axis=1)
878878

@@ -1078,7 +1078,7 @@ def _compute_multivariate_acovf_from_coefficients(
10781078

10791079
# Convert coefficients to a list of matrices, for use in
10801080
# `companion_matrix`; get dimensions
1081-
if type(coefficients) == list:
1081+
if type(coefficients) is list:
10821082
order = len(coefficients)
10831083
k_endog = coefficients[0].shape[0]
10841084
else:
@@ -1357,7 +1357,7 @@ def _compute_multivariate_pacf_from_coefficients(constrained, error_variance,
13571357
y_t = A_1 y_{t-1} + \dots + A_p y_{t-p} + \varepsilon_t
13581358
"""
13591359

1360-
if type(constrained) == list:
1360+
if type(constrained) is list:
13611361
order = len(constrained)
13621362
k_endog = constrained[0].shape[0]
13631363
else:
@@ -1414,7 +1414,7 @@ def unconstrain_stationary_multivariate(constrained, error_variance):
14141414
to Enforce Stationarity."
14151415
Journal of Statistical Computation and Simulation 24 (2): 99-106.
14161416
"""
1417-
use_list = type(constrained) == list
1417+
use_list = type(constrained) is list
14181418
if not use_list:
14191419
k_endog, order = constrained.shape
14201420
order //= k_endog

statsmodels/tsa/vector_ar/tests/JMulTi_results/parse_jmulti_vecm_output.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def sublists(lst, min_elmts=0, max_elmts=None):
8080
result = itertools.chain.from_iterable(
8181
itertools.combinations(lst, sublist_len)
8282
for sublist_len in range(min_elmts, max_elmts+1))
83-
if type(result) != list:
83+
if type(result) is not list:
8484
result = list(result)
8585
return result
8686

statsmodels/tsa/vector_ar/var_model.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ def test_causality(self, caused, causing=None, kind="f", signif=0.05):
19621962
"caused has to be of type string or int (or a "
19631963
"sequence of these types)."
19641964
)
1965-
caused = [self.names[c] if type(c) == int else c for c in caused]
1965+
caused = [self.names[c] if type(c) is int else c for c in caused]
19661966
caused_ind = [util.get_index(self.names, c) for c in caused]
19671967

19681968
if causing is not None:
@@ -1974,7 +1974,7 @@ def test_causality(self, caused, causing=None, kind="f", signif=0.05):
19741974
"causing has to be of type string or int (or "
19751975
"a sequence of these types) or None."
19761976
)
1977-
causing = [self.names[c] if type(c) == int else c for c in causing]
1977+
causing = [self.names[c] if type(c) is int else c for c in causing]
19781978
causing_ind = [util.get_index(self.names, c) for c in causing]
19791979
else:
19801980
causing_ind = [i for i in range(self.neqs) if i not in caused_ind]
@@ -2105,7 +2105,7 @@ def test_inst_causality(self, causing, signif=0.05):
21052105
"causing has to be of type string or int (or a "
21062106
+ "a sequence of these types)."
21072107
)
2108-
causing = [self.names[c] if type(c) == int else c for c in causing]
2108+
causing = [self.names[c] if type(c) is int else c for c in causing]
21092109
causing_ind = [util.get_index(self.names, c) for c in causing]
21102110

21112111
caused_ind = [i for i in range(self.neqs) if i not in causing_ind]

statsmodels/tsa/vector_ar/vecm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def select_coint_rank(
564564
)
565565

566566
if det_order not in [-1, 0, 1]:
567-
if type(det_order) == int and det_order > 1:
567+
if type(det_order) is int and det_order > 1:
568568
raise ValueError(
569569
"A det_order greather than 1 is not supported."
570570
"Use a value of -1, 0, or 1."
@@ -2023,7 +2023,7 @@ def test_granger_causality(self, caused, causing=None, signif=0.05):
20232023
"caused has to be of type string or int (or a "
20242024
"sequence of these types)."
20252025
)
2026-
caused = [self.names[c] if type(c) == int else c for c in caused]
2026+
caused = [self.names[c] if type(c) is int else c for c in caused]
20272027
caused_ind = [get_index(self.names, c) for c in caused]
20282028

20292029
if causing is not None:
@@ -2035,7 +2035,7 @@ def test_granger_causality(self, caused, causing=None, signif=0.05):
20352035
"causing has to be of type string or int (or "
20362036
"a sequence of these types) or None."
20372037
)
2038-
causing = [self.names[c] if type(c) == int else c for c in causing]
2038+
causing = [self.names[c] if type(c) is int else c for c in causing]
20392039
causing_ind = [get_index(self.names, c) for c in causing]
20402040

20412041
if causing is None:

0 commit comments

Comments
 (0)