Skip to content

Commit edf6519

Browse files
Report impossible constraints in SIMULATE.
Should make this mistake a little easier to understand than a divide-by-zero error.
1 parent 8f036f5 commit edf6519

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/bqlfn.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ def simulate(generator_id, metamodel, n):
449449
loglikelihoods = map(loglikelihood, generator_ids, metamodels)
450450
likelihoods = map(math.exp, loglikelihoods)
451451
total_likelihood = sum(likelihoods)
452+
if total_likelihood == 0:
453+
# XXX Show the constraints with symbolic names.
454+
raise BQLError(bdb, 'Impossible constraints: %r' % (constraints,))
452455
probabilities = [likelihood/total_likelihood for likelihood in likelihoods]
453456
countses = bdb.np_prng.multinomial(numpredictions, probabilities, size=1)
454457
counts = countses[0]

tests/test_codebook.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import crosscat.LocalEngine
2121

2222
import bayeslite
23+
24+
from bayeslite.exception import BQLError
2325
from bayeslite.metamodels.crosscat import CrosscatMetamodel
2426

2527

@@ -80,7 +82,7 @@ def test_codebook_value_map():
8082
('jackie', 18, 'LA'), ('rocker', 22, 'DC')
8183
''')
8284
bdb.execute('ANALYZE dummy_cc FOR 20 ITERATIONS WAIT')
83-
with pytest.raises(KeyError):
85+
with pytest.raises(BQLError):
8486
bdb.execute('SIMULATE age FROM dummy_pop GIVEN city = LA LIMIT 5')
8587

8688
def test_empty_codebook():

0 commit comments

Comments
 (0)