Skip to content

Commit e410f47

Browse files
committed
Merge remote-tracking branch 'origin/main' into breaking
2 parents 1b8f555 + c7bdc3f commit e410f47

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

HISTORY.md

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ The reason for this change is that there were several flavours of VarInfo.
8282
Some, like `typed_varinfo`, were easy to construct because we had convenience methods for them; however, the others were more difficult.
8383
This change makes it easier to access different VarInfo types, and also makes it more explicit which one you are constructing.
8484

85+
## 0.35.7
86+
87+
`check_model_and_trace` now errors if any NaN's are encountered when evaluating the model.
88+
8589
## 0.35.6
8690

8791
Fixed the implementation of `.~`, such that running a model with it no longer requires DynamicPPL itself to be loaded.

src/debug_utils.jl

+14-14
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,11 @@ function record_varname!(context::DebugContext, varname::VarName, dist)
231231
end
232232
end
233233

234-
# tilde
235-
_isassigned(x::AbstractArray, i) = isassigned(x, i)
236-
# HACK(torfjelde): Julia v1.7 only supports `isassigned(::AbstractArray, ::Int...)`.
237-
# TODO(torfjelde): Determine exactly in which version this change was introduced.
238-
if VERSION < v"v1.9.0-alpha1"
239-
_isassigned(x::AbstractArray, inds::Tuple) = isassigned(x, inds...)
240-
_isassigned(x::AbstractArray, idx::CartesianIndex) = _isassigned(x, Tuple(idx))
241-
end
242-
243234
_has_missings(x) = ismissing(x)
244235
function _has_missings(x::AbstractArray)
245236
# Can't just use `any` because `x` might contain `undef`.
246237
for i in eachindex(x)
247-
if _isassigned(x, i) && _has_missings(x[i])
238+
if isassigned(x, i) && _has_missings(x[i])
248239
return true
249240
end
250241
end
@@ -293,9 +284,18 @@ function record_pre_tilde_observe!(context::DebugContext, left, dist, varinfo)
293284
# Check for `missing`s; these should not end up here.
294285
if _has_missings(left)
295286
error(
296-
"Encountered missing value(s) in observe!\n" *
297-
"Remember that using `missing` to de-condition a variable is only " *
298-
"supported for univariate distributions, not for $dist",
287+
"Encountered `missing` value(s) on the left-hand side" *
288+
" of an observe statement. Using `missing` to de-condition" *
289+
" a variable is only supported for univariate distributions," *
290+
" not for $dist.",
291+
)
292+
end
293+
# Check for NaN's as well
294+
if any(isnan, left)
295+
error(
296+
"Encountered a NaN value on the left-hand side of an" *
297+
" observe statement; this may indicate that your data" *
298+
" contain NaN values.",
299299
)
300300
end
301301
end
@@ -474,7 +474,7 @@ end
474474
475475
Check that `model` is valid, warning about any potential issues.
476476
477-
See [`check_model_and_trace`](@ref) for more details on supported keword arguments
477+
See [`check_model_and_trace`](@ref) for more details on supported keyword arguments
478478
and details of which types of checks are performed.
479479
480480
# Returns

test/debug_utils.jl

+11
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@
123123
end
124124
end
125125

126+
@testset "NaN in data" begin
127+
@model function demo_nan_in_data(x)
128+
a ~ Normal()
129+
for i in eachindex(x)
130+
x[i] ~ Normal(a)
131+
end
132+
end
133+
model = demo_nan_in_data([1.0, NaN])
134+
@test_throws ErrorException check_model(model; error_on_failure=true)
135+
end
136+
126137
@testset "incorrect use of condition" begin
127138
@testset "missing in multivariate" begin
128139
@model function demo_missing_in_multivariate(x)

0 commit comments

Comments
 (0)