BUG: Raise TypeError for non-integer float observed data on discrete distributions#8285
Draft
kimjune01 wants to merge 4 commits into
Draft
BUG: Raise TypeError for non-integer float observed data on discrete distributions#8285kimjune01 wants to merge 4 commits into
kimjune01 wants to merge 4 commits into
Conversation
…iscrete distributions Fixes pymc-devs#8282. Discrete distributions (Binomial, Poisson, etc.) silently cast float observed values to integers via .astype(), truncating data without warning. Add a validation check in make_obs_var() that detects when float-to-integer casting would alter values. The check is narrowly scoped: - Only fires for concrete data (not symbolic Variables) - Only fires for float->integer dtype casts - Allows float arrays with exact integer values (e.g. [0.0, 1.0]) - Handles masked arrays via .compressed() - Handles scipy sparse matrices via .data attribute
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8285 +/- ##
==========================================
- Coverage 91.94% 91.94% -0.01%
==========================================
Files 125 125
Lines 20302 20314 +12
==========================================
+ Hits 18667 18678 +11
- Misses 1635 1636 +1
🚀 New features to boost your workflow:
|
main refactored scipy.sparse to a lazy module (sparse = lazy_scipy_module("sparse"))
and removed 'import scipy.sparse as sps'. Merging main left our new
make_obs_var check referencing the now-undefined 'sps'. Switch to the
'sparse' alias to match the current convention.
Author
|
Cannot validate on current setup, so drafting. Please close or take it over. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Model.make_obs_varsilently truncates float observed data to integers when the distribution has an integer dtype (e.g.Binomial,Poisson). This can produce wrong posteriors with no indication that anything went wrong.This PR adds a check in
make_obs_varthat raisesTypeErrorwhen float observed data contains non-integer values that would lose information on cast. Float arrays with exact integer values (e.g.[0.0, 1.0]) are still accepted, since this is a common pattern withfloatXdata.Handles
ndarray,MaskedArray, and sparse matrices.Closes #8282
Checklist
Type of change