Skip to content

Commit

Permalink
CLN: Enforce E721, use isinstance
Browse files Browse the repository at this point in the history
Use isinstance instead of comparing types
  • Loading branch information
bashtage committed Sep 12, 2018
1 parent 35ae4c3 commit 4478466
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,7 @@ select=
# E306: expected 1 blank line before a nested definition, found 0


E272
E272,
# E272: multiple spaces before keyword
E721
# E721: do not compare types, use 'isinstance()'
5 changes: 2 additions & 3 deletions statsmodels/base/tests/test_shrink_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,15 @@ def test_pickle_wrapper(self):
self.results._results.save(fh)
fh.seek(0, 0)
res_unpickled = self.results._results.__class__.load(fh)
assert_(type(res_unpickled) is type(self.results._results))
assert type(res_unpickled) is type(self.results._results) # noqa: E721

# test wrapped results load save
fh.seek(0, 0)
self.results.save(fh)
fh.seek(0, 0)
res_unpickled = self.results.__class__.load(fh)
fh.close()
# print type(res_unpickled)
assert_(type(res_unpickled) is type(self.results))
assert type(res_unpickled) is type(self.results) # noqa: E721

before = sorted(iterkeys(self.results.__dict__))
after = sorted(iterkeys(res_unpickled.__dict__))
Expand Down
3 changes: 2 additions & 1 deletion statsmodels/stats/mediation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
mediator, the results should be similar or identical to the earlier
Barron-Kenny approach.
"""
from statsmodels.compat.python import string_types

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -163,7 +164,7 @@ def _variable_pos(self, var, model):
return maybe_name_or_idx(self.mediator, mod)[1]

exp = self.exposure
exp_is_2 = ((len(exp) == 2) and (type(exp) != type('')))
exp_is_2 = ((len(exp) == 2) and not isinstance(exp, string_types))

if exp_is_2:
if model == 'outcome':
Expand Down
8 changes: 4 additions & 4 deletions statsmodels/tsa/base/tests/test_tsa_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def test_prediction_increment_pandas_dates():
assert_equal(start, 0)
assert_equal(end, nobs-1)
assert_equal(out_of_sample, 0)
assert_equal(type(prediction_index) == type(endog.index), True)
assert type(prediction_index) is type(endog.index) # noqa: E721
assert_equal(prediction_index.equals(mod._index), True)

# Negative index: [-2, end]
Expand All @@ -652,7 +652,7 @@ def test_prediction_increment_pandas_dates():
assert_equal(start, 3)
assert_equal(end, 4)
assert_equal(out_of_sample, 0)
assert_equal(type(prediction_index) == type(endog.index), True)
assert type(prediction_index) is type(endog.index) # noqa: E721
assert_equal(prediction_index.equals(mod._index[3:]), True)

# Forecasting: [1, 5]; the index is an extended version of the date index
Expand Down Expand Up @@ -699,7 +699,7 @@ def test_prediction_increment_pandas_dates_nanosecond():
assert_equal(start, 0)
assert_equal(end, nobs-1)
assert_equal(out_of_sample, 0)
assert_equal(type(prediction_index) == type(endog.index), True)
assert type(prediction_index) is type(endog.index) # noqa: E721
assert_equal(prediction_index.equals(mod._index), True)

# Negative index: [-2, end]
Expand All @@ -711,7 +711,7 @@ def test_prediction_increment_pandas_dates_nanosecond():
assert_equal(start, 3)
assert_equal(end, 4)
assert_equal(out_of_sample, 0)
assert_equal(type(prediction_index) == type(endog.index), True)
assert type(prediction_index) is type(endog.index) # noqa: E721
assert_equal(prediction_index.equals(mod._index[3:]), True)

# Forecasting: [1, 5]; the index is an extended version of the date index
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/tsa/tests/test_ar.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_pickle(self):
self.res1.save(fh)
fh.seek(0,0)
res_unpickled = self.res1.__class__.load(fh)
assert_(type(res_unpickled) is type(self.res1))
assert type(res_unpickled) is type(self.res1) # noqa: E721


class TestAROLSConstant(CheckARMixin):
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/tsa/tests/test_arima.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_pickle(self):
self.res1.save(fh)
fh.seek(0,0)
res_unpickled = self.res1.__class__.load(fh)
assert_(type(res_unpickled) is type(self.res1))
assert type(res_unpickled) is type(self.res1) # noqa: E721


class Test_Y_ARMA14_NoConst(CheckArmaResultsMixin):
Expand Down
4 changes: 2 additions & 2 deletions statsmodels/tsa/vector_ar/tests/test_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_names(self):
assert_equal(model2.endog_names, self.ref.names)

def test_get_eq_index(self):
assert(type(self.res.names) is list)
assert type(self.res.names) is list # noqa: E721

for i, name in enumerate(self.names):
idx = self.res.get_eq_index(i)
Expand Down Expand Up @@ -435,7 +435,7 @@ def test_pickle(self):
self.res.save(fh)
fh.seek(0,0)
res_unpickled = self.res.__class__.load(fh)
assert_(type(res_unpickled) is type(self.res))
assert type(res_unpickled) is type(self.res) # noqa: E721


class E1_Results(object):
Expand Down

0 comments on commit 4478466

Please sign in to comment.