Skip to content

Commit 62ab5db

Browse files
authored
Merge pull request #565 from stan-dev/remove-debug-print
Remove debug print statement
2 parents 07aa27d + 2d37270 commit 62ab5db

File tree

11 files changed

+39
-59
lines changed

11 files changed

+39
-59
lines changed

.pylintrc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ confidence=
6060
# --enable=similarities". If you want to run only the classes checker, but have
6161
# no Warning level messages displayed, use "--disable=all --enable=classes
6262
# --disable=W".
63-
disable=bad-continuation,
64-
consider-using-in,
63+
disable=consider-using-in,
6564
cyclic-import,
6665
fixme,
6766
import-outside-toplevel,
@@ -267,13 +266,6 @@ max-line-length=100
267266
# Maximum number of lines in a module.
268267
max-module-lines=5000
269268

270-
# List of optional constructs for which whitespace checking is disabled. `dict-
271-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
272-
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
273-
# `empty-line` allows space-only lines.
274-
no-space-check=trailing-comma,
275-
dict-separator
276-
277269
# Allow the body of a class to be on the same line as the declaration if body
278270
# contains single statement.
279271
single-line-class-stmt=no

cmdstanpy/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def sample(
11501150
sys.stdout.write('\n')
11511151
get_logger().info('CmdStan done processing.')
11521152

1153-
get_logger().debug('runset\n%s', runset.__repr__())
1153+
get_logger().debug('runset\n%s', repr(runset))
11541154

11551155
# hack needed to parse CSV files if model has no params
11561156
# needed if exe is supplied without stan file
@@ -1525,7 +1525,6 @@ def variational(
15251525
vb = CmdStanVB(runset)
15261526
return vb
15271527

1528-
# pylint: disable=no-self-use
15291528
def _run_cmdstan(
15301529
self,
15311530
runset: RunSet,

cmdstanpy/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ def get_latest_cmdstan(cmdstan_dir: str) -> Optional[str]:
132132
# unmunge as needed
133133
mmp = latest.split('.')
134134
if int(mmp[2]) < 0:
135-
print("here")
136135
rc_num = str(int(mmp[2]) + 100)
137136
mmp[2] = "0-rc" + rc_num
138137
latest = '.'.join(mmp)

test/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def assertRaisesRegexNested(self, exc, msg):
2424
exn_string += "\n" + str(exception)
2525
self.assertRegex(exn_string, msg)
2626

27-
# pylint: disable=no-self-use
2827
@contextlib.contextmanager
2928
def without_import(self, library, module):
3029
with unittest.mock.patch.dict('sys.modules', {library: None}):
@@ -33,7 +32,6 @@ def without_import(self, library, module):
3332
reload(module)
3433

3534
# recipe from https://stackoverflow.com/a/34333710
36-
# pylint: disable=no-self-use
3735
@contextlib.contextmanager
3836
def modified_environ(self, *remove, **update):
3937
"""

test/test_compiler_opts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Compiler options tests"""
22

3+
import logging
34
import os
45
import unittest
5-
import logging
66

77
from testfixtures import LogCapture
88

@@ -33,7 +33,7 @@ def test_opts_empty(self):
3333
opts = CompilerOptions()
3434
opts.validate()
3535
self.assertEqual(opts.compose(), [])
36-
self.assertEqual(opts.__repr__(), 'stanc_options={}, cpp_options={}')
36+
self.assertEqual(repr(opts), 'stanc_options={}, cpp_options={}')
3737

3838
stanc_opts = {}
3939
opts = CompilerOptions(stanc_options=stanc_opts)
@@ -48,7 +48,7 @@ def test_opts_empty(self):
4848
opts = CompilerOptions(stanc_options=stanc_opts, cpp_options=cpp_opts)
4949
opts.validate()
5050
self.assertEqual(opts.compose(), [])
51-
self.assertEqual(opts.__repr__(), 'stanc_options={}, cpp_options={}')
51+
self.assertEqual(repr(opts), 'stanc_options={}, cpp_options={}')
5252

5353
def test_opts_stanc(self):
5454
stanc_opts = {}

test/test_generate_quantities.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def test_from_csv_files(self):
3939
self.assertEqual(
4040
bern_gqs.runset._args.method, Method.GENERATE_QUANTITIES
4141
)
42-
self.assertIn('CmdStanGQ: model=bernoulli_ppc', bern_gqs.__repr__())
43-
self.assertIn('method=generate_quantities', bern_gqs.__repr__())
42+
self.assertIn('CmdStanGQ: model=bernoulli_ppc', repr(bern_gqs))
43+
self.assertIn('method=generate_quantities', repr(bern_gqs))
4444

4545
self.assertEqual(bern_gqs.runset.chains, 4)
4646
for i in range(bern_gqs.runset.chains):
@@ -128,8 +128,8 @@ def test_from_mcmc_sample(self):
128128
self.assertEqual(
129129
bern_gqs.runset._args.method, Method.GENERATE_QUANTITIES
130130
)
131-
self.assertIn('CmdStanGQ: model=bernoulli_ppc', bern_gqs.__repr__())
132-
self.assertIn('method=generate_quantities', bern_gqs.__repr__())
131+
self.assertIn('CmdStanGQ: model=bernoulli_ppc', repr(bern_gqs))
132+
self.assertIn('method=generate_quantities', repr(bern_gqs))
133133
self.assertEqual(bern_gqs.runset.chains, 4)
134134
for i in range(bern_gqs.runset.chains):
135135
self.assertEqual(bern_gqs.runset._retcode(i), 0)

test/test_model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def test_fixed_param(self):
9999
model = CmdStanModel(stan_file=stan)
100100
self.assertTrue(model._fixed_param)
101101

102-
# pylint: disable=no-self-use
103102
def test_model_pedantic(self):
104103
stan_file = os.path.join(DATAFILES_PATH, 'bernoulli_pedantic.stan')
105104
with LogCapture(level=logging.WARNING) as log:
@@ -313,7 +312,7 @@ def test_model_syntax_error(self):
313312

314313
def test_repr(self):
315314
model = CmdStanModel(stan_file=BERN_STAN)
316-
model_repr = model.__repr__()
315+
model_repr = repr(model)
317316
self.assertIn('name=bernoulli', model_repr)
318317

319318
def test_print(self):

test/test_optimize.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def test_instantiate(self):
3737
os.path.join(DATAFILES_PATH, 'optimize', 'rosenbrock_mle.csv')
3838
]
3939
mle = CmdStanMLE(runset)
40-
self.assertIn('CmdStanMLE: model=rosenbrock', mle.__repr__())
41-
self.assertIn('method=optimize', mle.__repr__())
40+
self.assertIn('CmdStanMLE: model=rosenbrock', repr(mle))
41+
self.assertIn('method=optimize', repr(mle))
4242
self.assertEqual(mle.column_names, ('lp__', 'x', 'y'))
4343
self.assertAlmostEqual(mle.optimized_params_dict['x'], 1, places=3)
4444
self.assertAlmostEqual(mle.optimized_params_dict['y'], 1, places=3)
@@ -48,8 +48,8 @@ def test_instantiate_from_csvfiles(self):
4848
DATAFILES_PATH, 'optimize', 'rosenbrock_mle.csv'
4949
)
5050
mle = from_csv(path=csvfiles_path)
51-
self.assertIn('CmdStanMLE: model=rosenbrock', mle.__repr__())
52-
self.assertIn('method=optimize', mle.__repr__())
51+
self.assertIn('CmdStanMLE: model=rosenbrock', repr(mle))
52+
self.assertIn('method=optimize', repr(mle))
5353
self.assertEqual(mle.column_names, ('lp__', 'x', 'y'))
5454
self.assertAlmostEqual(mle.optimized_params_dict['x'], 1, places=3)
5555
self.assertAlmostEqual(mle.optimized_params_dict['y'], 1, places=3)
@@ -59,8 +59,8 @@ def test_instantiate_from_csvfiles_save_iterations(self):
5959
DATAFILES_PATH, 'optimize', 'eight_schools_mle_iters.csv'
6060
)
6161
mle = from_csv(path=csvfiles_path)
62-
self.assertIn('CmdStanMLE: model=eight_schools', mle.__repr__())
63-
self.assertIn('method=optimize', mle.__repr__())
62+
self.assertIn('CmdStanMLE: model=eight_schools', repr(mle))
63+
self.assertIn('method=optimize', repr(mle))
6464
self.assertEqual(
6565
mle.column_names,
6666
(
@@ -89,8 +89,8 @@ def test_rosenbrock(self):
8989
stan = os.path.join(DATAFILES_PATH, 'optimize', 'rosenbrock.stan')
9090
model = CmdStanModel(stan_file=stan)
9191
mle = model.optimize(algorithm='LBFGS')
92-
self.assertIn('CmdStanMLE: model=rosenbrock', mle.__repr__())
93-
self.assertIn('method=optimize', mle.__repr__())
92+
self.assertIn('CmdStanMLE: model=rosenbrock', repr(mle))
93+
self.assertIn('method=optimize', repr(mle))
9494
self.assertTrue(mle.converged)
9595
self.assertEqual(mle.column_names, ('lp__', 'x', 'y'))
9696
self.assertAlmostEqual(mle.stan_variable('x'), 1, places=3)
@@ -152,8 +152,8 @@ def test_eight_schools(self):
152152
mle = model.optimize(
153153
data=rdata, algorithm='LBFGS', require_converged=False
154154
)
155-
self.assertIn('CmdStanMLE: model=eight_schools', mle.__repr__())
156-
self.assertIn('method=optimize', mle.__repr__())
155+
self.assertIn('CmdStanMLE: model=eight_schools', repr(mle))
156+
self.assertIn('method=optimize', repr(mle))
157157
self.assertFalse(mle.converged)
158158
with LogCapture() as log:
159159
self.assertEqual(mle.optimized_params_pd.shape, (1, 11))

test/test_runset.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ def test_check_repr(self):
2626
method_args=sampler_args,
2727
)
2828
runset = RunSet(args=cmdstan_args, chains=4)
29-
self.assertIn('RunSet: chains=4', runset.__repr__())
30-
self.assertIn('method=sample', runset.__repr__())
31-
self.assertIn('retcodes=[-1, -1, -1, -1]', runset.__repr__())
32-
self.assertIn('csv_file', runset.__repr__())
33-
self.assertIn('console_msgs', runset.__repr__())
34-
self.assertNotIn('diagnostics_file', runset.__repr__())
29+
self.assertIn('RunSet: chains=4', repr(runset))
30+
self.assertIn('method=sample', repr(runset))
31+
self.assertIn('retcodes=[-1, -1, -1, -1]', repr(runset))
32+
self.assertIn('csv_file', repr(runset))
33+
self.assertIn('console_msgs', repr(runset))
34+
self.assertNotIn('diagnostics_file', repr(runset))
3535

3636
def test_check_retcodes(self):
3737
exe = os.path.join(DATAFILES_PATH, 'bernoulli' + EXTENSION)

test/test_sample.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def test_bernoulli_good(self, stanfile='bernoulli.stan'):
6262
iter_sampling=100,
6363
show_progress=False,
6464
)
65-
self.assertIn('CmdStanMCMC: model=bernoulli', bern_fit.__repr__())
66-
self.assertIn('method=sample', bern_fit.__repr__())
65+
self.assertIn('CmdStanMCMC: model=bernoulli', repr(bern_fit))
66+
self.assertIn('method=sample', repr(bern_fit))
6767

6868
self.assertEqual(bern_fit.runset._args.method, Method.SAMPLE)
6969

@@ -99,8 +99,8 @@ def test_bernoulli_good(self, stanfile='bernoulli.stan'):
9999
metric='dense_e',
100100
show_progress=False,
101101
)
102-
self.assertIn('CmdStanMCMC: model=bernoulli', bern_fit.__repr__())
103-
self.assertIn('method=sample', bern_fit.__repr__())
102+
self.assertIn('CmdStanMCMC: model=bernoulli', repr(bern_fit))
103+
self.assertIn('method=sample', repr(bern_fit))
104104

105105
self.assertEqual(bern_fit.runset._args.method, Method.SAMPLE)
106106

@@ -221,7 +221,7 @@ def test_init_types(self):
221221
inits=1.1,
222222
show_progress=False,
223223
)
224-
self.assertIn('init=1.1', bern_fit.runset.__repr__())
224+
self.assertIn('init=1.1', repr(bern_fit.runset))
225225

226226
bern_fit = bern_model.sample(
227227
data=jdata,
@@ -233,7 +233,7 @@ def test_init_types(self):
233233
inits=1,
234234
show_progress=False,
235235
)
236-
self.assertIn('init=1', bern_fit.runset.__repr__())
236+
self.assertIn('init=1', repr(bern_fit.runset))
237237

238238
# Save init to json
239239
inits_path1 = os.path.join(_TMPDIR, 'inits_test_1.json')
@@ -255,7 +255,7 @@ def test_init_types(self):
255255
)
256256
self.assertIn(
257257
'init={}'.format(inits_path1.replace('\\', '\\\\')),
258-
bern_fit.runset.__repr__(),
258+
repr(bern_fit.runset),
259259
)
260260

261261
bern_fit = bern_model.sample(
@@ -270,7 +270,7 @@ def test_init_types(self):
270270
)
271271
self.assertIn(
272272
'init={}'.format(inits_path1.replace('\\', '\\\\')),
273-
bern_fit.runset.__repr__(),
273+
repr(bern_fit.runset),
274274
)
275275

276276
with self.assertRaises(ValueError):
@@ -317,7 +317,6 @@ def test_bernoulli_bad(self):
317317
bern_model.sample(data=jdata, chains=1, output_dir=path)
318318
os.rmdir(dirname1)
319319

320-
# pylint: disable=no-self-use
321320
def test_multi_proc_1(self):
322321
logistic_stan = os.path.join(DATAFILES_PATH, 'logistic.stan')
323322
logistic_model = CmdStanModel(stan_file=logistic_stan)
@@ -338,7 +337,6 @@ def test_multi_proc_1(self):
338337
('cmdstanpy', 'INFO', 'Chain [2] start processing'),
339338
)
340339

341-
# pylint: disable=no-self-use
342340
def test_multi_proc_2(self):
343341
logistic_stan = os.path.join(DATAFILES_PATH, 'logistic.stan')
344342
logistic_model = CmdStanModel(stan_file=logistic_stan)
@@ -615,7 +613,7 @@ def test_bernoulli_file_with_space(self):
615613

616614
def test_bernoulli_path_with_space(self):
617615
self.test_bernoulli_good(
618-
'path with space/' 'bernoulli_path_with_space.stan'
616+
'path with space/' + 'bernoulli_path_with_space.stan'
619617
)
620618

621619
def test_index_bounds_error(self):
@@ -922,7 +920,6 @@ def test_from_csv_fixed_param(self):
922920
fixed_param_sample = from_csv(path=csv_path)
923921
self.assertEqual(fixed_param_sample.draws_pd().shape, (100, 85))
924922

925-
# pylint: disable=no-self-use
926923
def test_custom_metric(self):
927924
stan = os.path.join(DATAFILES_PATH, 'bernoulli.stan')
928925
jdata = os.path.join(DATAFILES_PATH, 'bernoulli.data.json')

0 commit comments

Comments
 (0)