Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 0.43.0 (unreleased)

- `check_model` no longer throws an `isnan` MethodError for nonnumeric observations such as symbols.

`VarNamedTuple` records indexed random variables in same-type tuple templates ([#1539](https://github.com/TuringLang/DynamicPPL.jl/pull/1539)).

`fix` and `condition` now apply same-type tuple values to indexed variables: for `x = (0.0, 0.0); x[1] ~ Normal()`, `fix(model; x=(1.0, 2.0))` previously had no effect and now fixes `x[1]`. Mixed-type tuple values, such as `x=(1.0, 2)`, throw an `ArgumentError`, as does indexing into one stored in a `VarNamedTuple` ([#1539](https://github.com/TuringLang/DynamicPPL.jl/pull/1539)).
Expand Down
2 changes: 1 addition & 1 deletion src/debug_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Check if `x` is `NaN`, or contains any `NaN` values.
"""
_has_nans(x::NamedTuple) = any(_has_nans, x)
_has_nans(x::AbstractArray) = any(_has_nans, x)
_has_nans(x) = isnan(x)
_has_nans(x) = applicable(isnan, x) && isnan(x)
_has_nans(::Missing) = false

function DynamicPPL.accumulate_assume!!(
Expand Down
11 changes: 11 additions & 0 deletions test/debug_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ using DynamicPPL, Distributions, Test
using LinearAlgebra: I
using Random: Xoshiro

struct NaNObservation end
Base.isnan(::NaNObservation) = true

function test_model_fails_check(model)
issuccess = check_model(model)
@test !issuccess
Expand Down Expand Up @@ -122,6 +125,14 @@ end
@test_throws ErrorException check_model(m; error_on_failure=true)
end

@testset "non-numeric data" begin
@test !DynamicPPL.DebugUtils._has_nans((
label=:right, values=["left", missing, 1.0]
))
@test DynamicPPL.DebugUtils._has_nans((label=:right, values=["left", missing, NaN]))
@test DynamicPPL.DebugUtils._has_nans((label=:right, value=NaNObservation()))
end

@testset "incorrect use of condition" begin
@testset "missing in multivariate" begin
@model function demo_missing_in_multivariate(x)
Expand Down
Loading