Commit 1f044e7
Address PR #350 CI review round 4: P1 unused categorical levels trip balance check
**P1:** Round 3 added `observed=False` to the balance-check groupby to
silence a pandas FutureWarning, but that creates a false-unbalance bug:
on ordered-categorical `time_col` with extra category levels beyond the
observed periods, `observed=False` materializes zero-count unit-period
cells for the unused levels, and the balance check rejects the panel.
Fix: switched to `observed=True`. This tells categorical groupby to
count only OBSERVED unit-period cells, matching the `periods_list`
(observed uniques) that the rest of the validator is keyed to. No
change for numeric / datetime time columns.
**Test added:** `test_ordered_categorical_with_unused_levels_accepted`
declares categories `["pre0", "pre1", "pre2", "post1", "post2", "post3"]`
but only observes `{"pre1", "pre2", "post1", "post2"}`; asserts the
fit succeeds with `F="post1"` and `event_times=[-2, 0, 1]`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent cb11a1f commit 1f044e7
2 files changed
Lines changed: 51 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1110 | 1110 | | |
1111 | 1111 | | |
1112 | 1112 | | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
1116 | 1122 | | |
1117 | 1123 | | |
1118 | 1124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2865 | 2865 | | |
2866 | 2866 | | |
2867 | 2867 | | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
2868 | 2910 | | |
2869 | 2911 | | |
2870 | 2912 | | |
| |||
0 commit comments