Commit 736fdea
Address PR #350 CI review round 5: P2 to_dict JSON-safe
`HeterogeneousAdoptionDiDEventStudyResults.to_dict()` promised JSON-
serializable output but previously returned raw numpy scalars via
`list(ndarray)`, which `json.dumps` can't serialize. The `F` field and
`filter_info.F_last` could also hold numpy scalars or pandas
Timestamps that break serialization.
Fix:
- Per-horizon arrays use `.tolist()` (unwraps numpy scalars to native
Python).
- New `_json_safe_scalar` helper coerces numpy scalars via `.item()`
and pandas Timestamp/Timedelta via `.isoformat()`; everything else
passes through.
- New `_json_safe_filter_info` helper applies `_json_safe_scalar` to
`F_last` and each element of `dropped_cohorts`, and casts counts to
native `int`.
- `to_dict()` now applies these helpers consistently.
**Test added:** `test_to_dict_json_serializable` asserts
`json.dumps(result.to_dict())` succeeds and the round-trip values
parse back as native Python types (int, float, list).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1f044e7 commit 736fdea
2 files changed
Lines changed: 89 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
127 | 174 | | |
128 | 175 | | |
129 | 176 | | |
| |||
591 | 638 | | |
592 | 639 | | |
593 | 640 | | |
594 | | - | |
595 | | - | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
596 | 648 | | |
597 | 649 | | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
607 | 659 | | |
608 | 660 | | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
613 | 665 | | |
614 | 666 | | |
615 | 667 | | |
616 | | - | |
| 668 | + | |
617 | 669 | | |
618 | 670 | | |
619 | 671 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2576 | 2576 | | |
2577 | 2577 | | |
2578 | 2578 | | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
2579 | 2600 | | |
2580 | 2601 | | |
2581 | 2602 | | |
| |||
0 commit comments