Skip to content

Commit 985099d

Browse files
authored
Formatted 15 Files of test Dir (#4149)
* Formatted 15 Files of test Dir * Used pre-commit run
1 parent 6f3193d commit 985099d

15 files changed

+451
-431
lines changed

pymc3/distributions/continuous.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ def assert_negative_support(var, label, distname, value=-1e-6):
134134
support = False
135135

136136
if np.any(support):
137-
msg = "The variable specified for {} has negative support for {}, ".format(
138-
label, distname
139-
)
137+
msg = f"The variable specified for {label} has negative support for {distname}, "
140138
msg += "likely making it unsuitable for this parameter."
141139
warnings.warn(msg)
142140

@@ -712,7 +710,7 @@ def random(self, point=None, size=None):
712710
)
713711

714712
def _random(self, mu, sigma, lower, upper, size):
715-
""" Wrapper around stats.truncnorm.rvs that converts TruncatedNormal's
713+
"""Wrapper around stats.truncnorm.rvs that converts TruncatedNormal's
716714
parametrization to scipy.truncnorm. All parameter arrays should have
717715
been broadcasted properly by generate_samples at this point and size is
718716
the scipy.rvs representation.
@@ -3447,7 +3445,7 @@ def random(self, point=None, size=None):
34473445
)
34483446

34493447
def _random(self, c, lower, upper, size):
3450-
""" Wrapper around stats.triang.rvs that converts Triangular's
3448+
"""Wrapper around stats.triang.rvs that converts Triangular's
34513449
parametrization to scipy.triang. All parameter arrays should have
34523450
been broadcasted properly by generate_samples at this point and size is
34533451
the scipy.rvs representation.
@@ -3706,7 +3704,7 @@ def __init__(self, nu=None, sigma=None, b=None, sd=None, *args, **kwargs):
37063704
self.sigma = self.sd = sigma = tt.as_tensor_variable(floatX(sigma))
37073705
self.b = b = tt.as_tensor_variable(floatX(b))
37083706

3709-
nu_sigma_ratio = -nu ** 2 / (2 * sigma ** 2)
3707+
nu_sigma_ratio = -(nu ** 2) / (2 * sigma ** 2)
37103708
self.mean = (
37113709
sigma
37123710
* np.sqrt(np.pi / 2)
@@ -3762,7 +3760,7 @@ def random(self, point=None, size=None):
37623760
return generate_samples(self._random, nu=nu, sigma=sigma, dist_shape=self.shape, size=size)
37633761

37643762
def _random(self, nu, sigma, size):
3765-
""" Wrapper around stats.rice.rvs that converts Rice's
3763+
"""Wrapper around stats.rice.rvs that converts Rice's
37663764
parametrization to scipy.rice. All parameter arrays should have
37673765
been broadcasted properly by generate_samples at this point and size is
37683766
the scipy.rvs representation.

pymc3/tests/backend_fixtures.py

Lines changed: 108 additions & 110 deletions
Large diffs are not rendered by default.

pymc3/tests/conftest.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,29 @@
2020

2121
@pytest.fixture(scope="function", autouse=True)
2222
def theano_config():
23-
config = theano.configparser.change_flags(compute_test_value='raise')
23+
config = theano.configparser.change_flags(compute_test_value="raise")
2424
with config:
2525
yield
2626

2727

28-
@pytest.fixture(scope='function', autouse=True)
28+
@pytest.fixture(scope="function", autouse=True)
2929
def exception_verbosity():
30-
config = theano.configparser.change_flags(
31-
exception_verbosity='high')
30+
config = theano.configparser.change_flags(exception_verbosity="high")
3231
with config:
3332
yield
3433

3534

36-
@pytest.fixture(scope='function', autouse=False)
35+
@pytest.fixture(scope="function", autouse=False)
3736
def strict_float32():
38-
if theano.config.floatX == 'float32':
39-
config = theano.configparser.change_flags(
40-
warn_float64='raise')
37+
if theano.config.floatX == "float32":
38+
config = theano.configparser.change_flags(warn_float64="raise")
4139
with config:
4240
yield
4341
else:
4442
yield
4543

4644

47-
@pytest.fixture(scope='function', autouse=False)
45+
@pytest.fixture(scope="function", autouse=False)
4846
def seeded_test():
4947
# TODO: use this instead of SeededTest
5048
np.random.seed(42)

pymc3/tests/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def matches(self, **kwargs):
6565

6666
class Matcher:
6767

68-
_partial_matches = ('msg', 'message')
68+
_partial_matches = ("msg", "message")
6969

7070
def matches(self, d, **kwargs):
7171
"""
@@ -91,7 +91,7 @@ def match_value(self, k, dv, v):
9191
if isinstance(v, type(dv)):
9292
result = False
9393
elif not isinstance(dv, str) or k not in self._partial_matches:
94-
result = (v == dv)
94+
result = v == dv
9595
else:
9696
result = dv.find(v) >= 0
9797
return result

pymc3/tests/models.py

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ def simple_model():
2626
mu = -2.1
2727
tau = 1.3
2828
with Model() as model:
29-
Normal('x', mu, tau=tau, shape=2, testval=tt.ones(2) * .1)
29+
Normal("x", mu, tau=tau, shape=2, testval=tt.ones(2) * 0.1)
3030

31-
return model.test_point, model, (mu, tau ** -.5)
31+
return model.test_point, model, (mu, tau ** -0.5)
3232

3333

3434
def simple_categorical():
3535
p = floatX_array([0.1, 0.2, 0.3, 0.4])
3636
v = floatX_array([0.0, 1.0, 2.0, 3.0])
3737
with Model() as model:
38-
Categorical('x', p, shape=3, testval=[1, 2, 3])
38+
Categorical("x", p, shape=3, testval=[1, 2, 3])
3939

4040
mu = np.dot(p, v)
4141
var = np.dot(p, (v - mu) ** 2)
@@ -46,9 +46,9 @@ def multidimensional_model():
4646
mu = -2.1
4747
tau = 1.3
4848
with Model() as model:
49-
Normal('x', mu, tau=tau, shape=(3, 2), testval=.1 * tt.ones((3, 2)))
49+
Normal("x", mu, tau=tau, shape=(3, 2), testval=0.1 * tt.ones((3, 2)))
5050

51-
return model.test_point, model, (mu, tau ** -.5)
51+
return model.test_point, model, (mu, tau ** -0.5)
5252

5353

5454
def simple_arbitrary_det():
@@ -59,50 +59,52 @@ def arbitrary_det(value):
5959
return value
6060

6161
with Model() as model:
62-
a = Normal('a')
62+
a = Normal("a")
6363
b = arbitrary_det(a)
64-
Normal('obs', mu=b.astype('float64'), observed=floatX_array([1, 3, 5]))
64+
Normal("obs", mu=b.astype("float64"), observed=floatX_array([1, 3, 5]))
6565

6666
return model.test_point, model
6767

6868

6969
def simple_init():
7070
start, model, moments = simple_model()
71-
step = Metropolis(model.vars, np.diag([1.]), model=model)
71+
step = Metropolis(model.vars, np.diag([1.0]), model=model)
7272
return model, start, step, moments
7373

7474

7575
def simple_2model():
7676
mu = -2.1
7777
tau = 1.3
78-
p = .4
78+
p = 0.4
7979
with Model() as model:
80-
x = pm.Normal('x', mu, tau=tau, testval=.1)
81-
pm.Deterministic('logx', tt.log(x))
82-
pm.Bernoulli('y', p)
80+
x = pm.Normal("x", mu, tau=tau, testval=0.1)
81+
pm.Deterministic("logx", tt.log(x))
82+
pm.Bernoulli("y", p)
8383
return model.test_point, model
8484

8585

8686
def simple_2model_continuous():
8787
mu = -2.1
8888
tau = 1.3
8989
with Model() as model:
90-
x = pm.Normal('x', mu, tau=tau, testval=.1)
91-
pm.Deterministic('logx', tt.log(x))
92-
pm.Beta('y', alpha=1, beta=1, shape=2)
90+
x = pm.Normal("x", mu, tau=tau, testval=0.1)
91+
pm.Deterministic("logx", tt.log(x))
92+
pm.Beta("y", alpha=1, beta=1, shape=2)
9393
return model.test_point, model
9494

9595

9696
def mv_simple():
97-
mu = floatX_array([-.1, .5, 1.1])
98-
p = floatX_array([
99-
[2., 0, 0],
100-
[.05, .1, 0],
101-
[1., -0.05, 5.5]])
97+
mu = floatX_array([-0.1, 0.5, 1.1])
98+
p = floatX_array([[2.0, 0, 0], [0.05, 0.1, 0], [1.0, -0.05, 5.5]])
10299
tau = np.dot(p, p.T)
103100
with pm.Model() as model:
104-
pm.MvNormal('x', tt.constant(mu), tau=tt.constant(tau),
105-
shape=3, testval=floatX_array([.1, 1., .8]))
101+
pm.MvNormal(
102+
"x",
103+
tt.constant(mu),
104+
tau=tt.constant(tau),
105+
shape=3,
106+
testval=floatX_array([0.1, 1.0, 0.8]),
107+
)
106108
H = tau
107109
C = np.linalg.inv(H)
108110
return model.test_point, model, (mu, C)
@@ -145,9 +147,9 @@ def mv_simple_very_coarse():
145147
def mv_simple_discrete():
146148
d = 2
147149
n = 5
148-
p = floatX_array([.15, .85])
150+
p = floatX_array([0.15, 0.85])
149151
with pm.Model() as model:
150-
pm.Multinomial('x', n, tt.constant(p), shape=d, testval=np.array([1, 4]))
152+
pm.Multinomial("x", n, tt.constant(p), shape=d, testval=np.array([1, 4]))
151153
mu = n * p
152154
# covariance matrix
153155
C = np.zeros((d, d))
@@ -180,30 +182,29 @@ def mv_prior_simple():
180182
std_post = (K - np.dot(v.T, v)).diagonal() ** 0.5
181183

182184
with pm.Model() as model:
183-
x = pm.Flat('x', shape=n)
184-
x_obs = pm.MvNormal('x_obs', observed=obs, mu=x,
185-
cov=noise * np.eye(n), shape=n)
185+
x = pm.Flat("x", shape=n)
186+
x_obs = pm.MvNormal("x_obs", observed=obs, mu=x, cov=noise * np.eye(n), shape=n)
186187

187188
return model.test_point, model, (K, L, mu_post, std_post, noise)
188189

189190

190191
def non_normal(n=2):
191192
with pm.Model() as model:
192-
pm.Beta('x', 3, 3, shape=n, transform=None)
193-
return model.test_point, model, (np.tile([.5], n), None)
193+
pm.Beta("x", 3, 3, shape=n, transform=None)
194+
return model.test_point, model, (np.tile([0.5], n), None)
194195

195196

196197
def exponential_beta(n=2):
197198
with pm.Model() as model:
198-
pm.Beta('x', 3, 1, shape=n, transform=None)
199-
pm.Exponential('y', 1, shape=n, transform=None)
199+
pm.Beta("x", 3, 1, shape=n, transform=None)
200+
pm.Exponential("y", 1, shape=n, transform=None)
200201
return model.test_point, model, None
201202

202203

203204
def beta_bernoulli(n=2):
204205
with pm.Model() as model:
205-
pm.Beta('x', 3, 1, shape=n, transform=None)
206-
pm.Bernoulli('y', 0.5)
206+
pm.Beta("x", 3, 1, shape=n, transform=None)
207+
pm.Bernoulli("y", 0.5)
207208
return model.test_point, model, None
208209

209210

0 commit comments

Comments
 (0)