Skip to content

Commit f4fb6a2

Browse files
committed
MAINT: Fix automatically documented issues
Fix a number of small issues found with auto code analysis tool
1 parent 321e160 commit f4fb6a2

39 files changed

+96
-86
lines changed

archive/docs/fix_longtable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
read_file_path = os.path.join(BUILDDIR,'latex','statsmodels.tex')
88
write_file_path = os.path.join(BUILDDIR, 'latex','statsmodels_tmp.tex')
99

10-
read_file = open(read_file_path,'r')
11-
write_file = open(write_file_path, 'w')
10+
read_file = open(read_file_path, 'r', encoding="utf-8")
11+
write_file = open(write_file_path, 'w', encoding="utf-8")
1212

1313
for line in read_file:
1414
if 'longtable}{LL' in line:

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@
405405
# ghissue config
406406
github_project_url = 'https://github.com/statsmodels/statsmodels'
407407

408-
example_context = yaml.safe_load(open('examples/landing.yml'))
408+
example_context = yaml.safe_load(open('examples/landing.yml', encoding="utf-8"))
409409
html_context.update({'examples': example_context})
410410

411411
# --------------- DOCTEST -------------------

examples/python/generic_mle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def nloglikeobs(self, params):
130130
def fit(self, start_params=None, maxiter=10000, maxfun=5000, **kwds):
131131
# we have one additional parameter and we need to add it for summary
132132
self.exog_names.append('alpha')
133-
if start_params == None:
133+
if start_params is None:
134134
# Reasonable starting values
135135
start_params = np.append(np.zeros(self.exog.shape[1]), .5)
136136
# intercept

examples/run_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def no_show(*args):
2828
EXAMPLE_FILES = glob.glob('python/*.py')
2929
for example in EXAMPLE_FILES:
3030
KNOWN_BAD_FILE = any([bf in example for bf in BAD_FILES])
31-
with open(example, 'r') as pyfile:
31+
with open(example, 'r', encoding="utf-8") as pyfile:
3232
code = pyfile.read()
3333
try:
3434
sys.stdout = REDIRECT_STDOUT

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# These are strictly installation requirements. Builds requirements are
5151
# managed in pyproject.toml
5252
INSTALL_REQUIRES = []
53-
with open("requirements.txt") as req:
53+
with open("requirements.txt", encoding="utf-8") as req:
5454
for line in req.readlines():
5555
INSTALL_REQUIRES.append(line.split("#")[0].strip())
5656

@@ -266,11 +266,11 @@ def check_source(source_name):
266266
def process_tempita(source_name):
267267
"""Runs pyx.in files through tempita is needed"""
268268
if source_name.endswith("pyx.in"):
269-
with open(source_name, "r") as templated:
269+
with open(source_name, "r", encoding="utf-8") as templated:
270270
pyx_template = templated.read()
271271
pyx = Tempita.sub(pyx_template)
272272
pyx_filename = source_name[:-3]
273-
with open(pyx_filename, "w") as pyx_file:
273+
with open(pyx_filename, "w", encoding="utf-8") as pyx_file:
274274
pyx_file.write(pyx)
275275
file_stats = os.stat(source_name)
276276
try:

statsmodels/base/tests/test_penalized.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def setup_class(cls):
6767
cls._initialize()
6868

6969
@classmethod
70-
def _generate_endog(self, linpred):
70+
def _generate_endog(cls, linpred):
7171
mu = np.exp(linpred)
7272
np.random.seed(999)
7373
y = np.random.poisson(mu)
@@ -404,7 +404,7 @@ def test_cov_type(self):
404404
class CheckPenalizedLogit(CheckPenalizedPoisson):
405405

406406
@classmethod
407-
def _generate_endog(self, linpred):
407+
def _generate_endog(cls, linpred):
408408
mu = 1 / (1 + np.exp(-linpred + linpred.mean() - 0.5))
409409
np.random.seed(999)
410410
y = np.random.rand(len(mu)) < mu
@@ -517,7 +517,7 @@ def test_zeros(self):
517517
class CheckPenalizedBinomCount(CheckPenalizedPoisson):
518518

519519
@classmethod
520-
def _generate_endog(self, linpred):
520+
def _generate_endog(cls, linpred):
521521
mu = 1 / (1 + np.exp(-linpred + linpred.mean() - 0.5))
522522
np.random.seed(999)
523523
n_trials = 5 * np.ones(len(mu), int)
@@ -614,7 +614,7 @@ def _initialize(cls):
614614
class CheckPenalizedGaussian(CheckPenalizedPoisson):
615615

616616
@classmethod
617-
def _generate_endog(self, linpred):
617+
def _generate_endog(cls, linpred):
618618
sig_e = np.sqrt(0.1)
619619
np.random.seed(999)
620620
y = linpred + sig_e * np.random.rand(len(linpred))

statsmodels/datasets/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def _get_cache(cache):
119119

120120
def _cache_it(data, cache_path):
121121
import zlib
122-
open(cache_path, "wb").write(zlib.compress(data))
122+
with open(cache_path, "wb") as zf:
123+
zf.write(zlib.compress(data))
123124

124125

125126
def _open_cache(cache_path):

statsmodels/discrete/tests/test_discrete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ def test_issue_339():
16171617
smry = "\n".join(res1.summary().as_text().split('\n')[9:])
16181618
cur_dir = os.path.dirname(os.path.abspath(__file__))
16191619
test_case_file = os.path.join(cur_dir, 'results', 'mn_logit_summary.txt')
1620-
with open(test_case_file, 'r') as fd:
1620+
with open(test_case_file, 'r', encoding="utf-8") as fd:
16211621
test_case = fd.read()
16221622
np.testing.assert_equal(smry, test_case[:-1])
16231623
# smoke test for summary2

statsmodels/examples/ex_lowess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
rpath = os.path.split(statsmodels.nonparametric.tests.results.__file__)[0]
6666
rfile = os.path.join(rpath, 'test_lowess_frac.csv')
6767
test_data = np.genfromtxt(open(rfile, 'rb'),
68-
delimiter = ',', names = True)
68+
delimiter=',', names=True)
6969
expected_lowess_23 = np.array([test_data['x'], test_data['out_2_3']]).T
7070
expected_lowess_15 = np.array([test_data['x'], test_data['out_1_5']]).T
7171

statsmodels/examples/run_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def noop(*args):
4949
try:
5050
print("\n\nExecuting example file", run_all_f)
5151
print("-----------------------" + "-"*len(run_all_f))
52-
exec(open(run_all_f).read())
52+
exec(open(run_all_f, encoding="utf-8").read())
5353
except:
5454
#f might be overwritten in the executed file
5555
print("**********************" + "*"*len(run_all_f))

0 commit comments

Comments
 (0)