Commit ce73058
Address local AI review (Wave 2): exact dose-invariance, tolerance-aware integer detection
P1 from local review (`treatment_dose.is_time_invariant`):
- Removed `np.round(..., 8)` tolerance from `_compute_treatment_dose`'s
per-unit non-zero distinct-count check. The documented contract is
"per-unit non-zero doses have at most one distinct value" (exact),
but the implementation was rounding to 8 decimals before comparing,
silently classifying tiny-but-real dose variation as time-invariant
and contradicting the docstring + CHANGELOG + autonomous guide §2.
Now uses exact `np.unique(unit_nonzero).size > 1`. Added a regression
test (`test_treatment_dose_distinguishes_doses_at_high_precision`) for
a unit with two non-equal doses separated by 1e-9 (sub the previous
rounding window) — asserts `is_time_invariant=False`.
Related dead-code removal:
- Removed the `len(nonzero) == 0` defensive branch in
`_compute_treatment_dose`. `treatment_type == "continuous"` is reached
only when the treatment column has more than two distinct values OR
a 2-valued numeric outside `{0, 1}`; an all-zero numeric column is
classified as `binary_absorbing` and never reaches this branch, so
`nonzero` is guaranteed non-empty. Removing the branch eliminates
the NaN-vs-Optional[float] inconsistency the reviewer flagged on
`dose_min/max/mean`.
P2 from local review (`is_integer_valued` brittleness):
- Switched from `np.equal(np.mod(arr, 1.0), 0.0)` to
`np.isclose(arr, np.round(arr), rtol=0.0, atol=1e-12)`. The treatment
/ outcome column is user input (system boundary), and CSV-roundtripped
count columns commonly carry float64 representation noise (e.g.,
`1.0` stored as `1.0000000000000002`). Tolerance-aware integer
detection is the right discipline at the boundary; downstream the
`is_count_like` heuristic remains gated on this AND `pct_zeros > 0`
AND `skewness > 0.5` AND `n_distinct > 2`, so isolated noise can't
flip the classification.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 335de3d commit ce73058
2 files changed
Lines changed: 50 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
613 | 613 | | |
614 | 614 | | |
615 | 615 | | |
616 | | - | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
617 | 621 | | |
618 | 622 | | |
619 | 623 | | |
| |||
672 | 676 | | |
673 | 677 | | |
674 | 678 | | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
675 | 684 | | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
684 | 688 | | |
685 | 689 | | |
686 | 690 | | |
687 | 691 | | |
688 | 692 | | |
689 | 693 | | |
690 | 694 | | |
691 | | - | |
692 | | - | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
693 | 701 | | |
694 | 702 | | |
695 | 703 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1075 | 1075 | | |
1076 | 1076 | | |
1077 | 1077 | | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
1078 | 1109 | | |
1079 | 1110 | | |
1080 | 1111 | | |
| |||
0 commit comments