Skip to content

Commit fb50e9c

Browse files
authored
Allow passing name as kwarg to pm.Bound RVs (#3152)
This fails without this patch: BoundPoisson = pm.Bound(pm.Poisson, upper = 6) y = BoundPoisson(name="y", mu=1)
1 parent 07592eb commit fb50e9c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pymc3/distributions/bound.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,23 @@ def __init__(self, distribution, lower=None, upper=None):
201201
self.lower = lower
202202
self.upper = upper
203203

204-
def __call__(self, *args, **kwargs):
204+
def __call__(self, name, *args, **kwargs):
205205
if 'observed' in kwargs:
206206
raise ValueError('Observed Bound distributions are not supported. '
207207
'If you want to model truncated data '
208208
'you can use a pm.Potential in combination '
209209
'with the cumulative probability function. See '
210210
'pymc3/examples/censored_data.py for an example.')
211-
first, args = args[0], args[1:]
212211

213212
if issubclass(self.distribution, Continuous):
214-
return _ContinuousBounded(first, self.distribution,
213+
return _ContinuousBounded(name, self.distribution,
215214
self.lower, self.upper, *args, **kwargs)
216215
elif issubclass(self.distribution, Discrete):
217-
return _DiscreteBounded(first, self.distribution,
216+
return _DiscreteBounded(name, self.distribution,
218217
self.lower, self.upper, *args, **kwargs)
219218
else:
220-
raise ValueError('Distribution is neither continuous nor discrete.')
219+
raise ValueError(
220+
'Distribution is neither continuous nor discrete.')
221221

222222
def dist(self, *args, **kwargs):
223223
if issubclass(self.distribution, Continuous):

pymc3/tests/test_distributions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,10 @@ def test_bound():
11831183
assert rand.dtype in [np.int16, np.int32, np.int64]
11841184
assert rand >= 5 and rand <= 8
11851185

1186+
with Model():
1187+
BoundPoisson = Bound(Poisson, upper=6)
1188+
BoundPoisson(name="y", mu=1)
1189+
11861190

11871191
class TestLatex(object):
11881192

0 commit comments

Comments
 (0)