Skip to content

Commit 12de79c

Browse files
committed
Raise informative error when passing masked data to Data
1 parent cb2c77f commit 12de79c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pymc/data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ def Data(
423423
# `convert_observed_data` takes care of parameter `value` and
424424
# transforms it to something digestible for PyTensor.
425425
arr = convert_observed_data(value)
426+
if isinstance(arr, np.ma.MaskedArray):
427+
raise NotImplementedError(
428+
"Masked arrays or arrays with `nan` entries are not supported. "
429+
"Pass them directly to `observed` if you want to trigger auto-imputation"
430+
)
426431

427432
if mutable is None:
428433
warnings.warn(

tests/test_data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ def test_data_mutable_default_warning(self):
437437
assert isinstance(data, pt.TensorConstant)
438438
pass
439439

440+
def test_masked_array_error(self):
441+
with pm.Model():
442+
with pytest.raises(
443+
NotImplementedError,
444+
match="Masked arrays or arrays with `nan` entries are not supported.",
445+
):
446+
pm.ConstantData("x", [0, 1, np.nan, 2])
447+
440448

441449
def test_data_naming():
442450
"""

0 commit comments

Comments
 (0)