Describe the issue:
When using discrete distributions (e.g. pm.Binomial or pm.Poisson), PyMC silently accepts floating-point arrays as observed values and casts them to integers without any warning. Since floats are outside the support of these distributions, PyMC should either raise an error or at minimum emit a warning when the observed dtype does not match the distribution's expected integer dtype.
Original Binomial observed values: [0.10999999940395355, 1.5, 2.890000104904175]
Model stored Binomial observations: [0, 1, 2]
Original Poisson observed values: [0.20000000298023224, 1.7000000476837158, 3.0999999046325684]
Model stored Poisson observations: [0, 1, 3]
Reproduceable code example:
import numpy as np
import pymc as pm
observed_binom = np.array([0.11, 1.5, 2.89], dtype=np.float32)
observed_pois = np.array([0.2, 1.7, 3.1], dtype=np.float32)
with pm.Model() as model:
p = pm.Beta("p", alpha=1.0, beta=1.0)
pm.Binomial("x", n=5, p=p, observed=observed_binom)
mu = pm.HalfNormal("mu", sigma=2.0)
pm.Poisson("y", mu=mu, observed=observed_pois)
stored_observed_binom = model["x"].tag.observations.eval()
stored_observed_pois = model["y"].tag.observations.eval()
print("Original Binomial observed values:", observed_binom.tolist())
print("Model stored Binomial observations:", stored_observed_binom.tolist())
print("Original Poisson observed values:", observed_pois.tolist())
print("Model stored Poisson observations:", stored_observed_pois.tolist())
pm.sample(
draws=50,
tune=50,
chains=1,
cores=1,
random_seed=123,
progressbar=False,
)
Error message:
PyMC version information:
PyMC: 5.28.5
Installed via uv (pypi)
[project]
name = "pymc-float-observed-repro"
version = "0.1.0"
description = "Minimal repro: discrete observed floats accepted"
requires-python = ">=3.10"
dependencies = [
"pymc",
"numpy",
]
[tool.uv]
package = false
Context for the issue:
Silent dtype coercion may lead to a situation where users accidentally pass continuous values to a discrete likelihood and get incorrect evaluations with no indication that anything is wrong.
Describe the issue:
When using discrete distributions (e.g.
pm.Binomialorpm.Poisson), PyMC silently accepts floating-point arrays as observed values and casts them to integers without any warning. Since floats are outside the support of these distributions, PyMC should either raise an error or at minimum emit a warning when the observed dtype does not match the distribution's expected integer dtype.Reproduceable code example:
Error message:
PyMC version information:
PyMC: 5.28.5
Installed via uv (pypi)
[project]
name = "pymc-float-observed-repro"
version = "0.1.0"
description = "Minimal repro: discrete observed floats accepted"
requires-python = ">=3.10"
dependencies = [
"pymc",
"numpy",
]
[tool.uv]
package = false
Context for the issue:
Silent dtype coercion may lead to a situation where users accidentally pass continuous values to a discrete likelihood and get incorrect evaluations with no indication that anything is wrong.