Skip to content

Commit

Permalink
Test for aeppl warning about missing RV
Browse files Browse the repository at this point in the history
This adapts to the change in behavior introduced in
aesara-devs/aeppl#151.
  • Loading branch information
maresb committed Jul 7, 2022
1 parent 6014e8f commit b235941
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pymc/tests/test_logprob.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings

import aesara
import aesara.tensor as at
import numpy as np
Expand Down Expand Up @@ -333,11 +335,17 @@ def logp(value, x):
with Model() as m:
x = Normal.dist()
y = DensityDist("y", x, logp=logp)
# Aeppl raises a KeyError when it finds an unexpected RV
with pytest.raises(KeyError):
joint_logp([y], {y: y.type()})
with pytest.warns(
UserWarning,
match="Found a random variable that was neither among the observations "
"nor the conditioned variables",
):
assert joint_logp([y], {y: y.type()})

# The above warning should go away with ignore_logprob.
with Model() as m:
x = ignore_logprob(Normal.dist())
y = DensityDist("y", x, logp=logp)
assert joint_logp([y], {y: y.type()})
with warnings.catch_warnings():
warnings.simplefilter("error")
assert joint_logp([y], {y: y.type()})

0 comments on commit b235941

Please sign in to comment.