Commit cb11a1f
Address PR #350 CI review round 3: P0 chronological cohort sort + P3 docstrings
**P0 (cohort sort key):** `_validate_had_panel_event_study` sorted
first_treat_col values with raw Python `(x is None, x)` while `time_col`
was already required to be ordered (numeric/datetime/ordered
categorical). On ordered-categorical staggered panels where
chronological order differs from lexicographic order, `F_last =
cohorts[-1]` silently picked the lexicographically latest cohort,
not the chronologically latest. That keeps the wrong cohort and
returns event-study estimates for the wrong estimand.
Fix: Promoted the dtype-aware `_sort_key` (ordered-categorical uses
declared category index; numeric/datetime use natural order) to the
top of the validator, just after the time-dtype check. Cohort
sorting, pre/post period sorting, contiguity check, and the
staggered-without-first_treat detection all now share this single
`_sort_key`. Removed the duplicate `_sort_key` definition that was
sitting further down in the same function.
**P3 (stale docstrings):**
- `fit()` no longer opens with "two-period panel"; now describes both
aggregation modes with links to the respective result classes.
- `HeterogeneousAdoptionDiDEventStudyResults.n_units` docstring no
longer says "only last-cohort units"; now accurately reports
last-cohort PLUS never-treated retained.
**Test added:** `test_staggered_ordered_categorical_chooses_chronological_last`
uses categories `["q1", "q2", "q3", "q10"]` where lex max of the two
cohorts (`"q2", "q10"`) is `"q2"` but chronological last is `"q10"`;
asserts the fix picks `"q10"` as `F_last` and retains only the
q10-cohort units.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 6e321ad commit cb11a1f
2 files changed
Lines changed: 108 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
449 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
450 | 452 | | |
451 | 453 | | |
452 | 454 | | |
| |||
933 | 935 | | |
934 | 936 | | |
935 | 937 | | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
936 | 957 | | |
937 | 958 | | |
938 | 959 | | |
| |||
1005 | 1026 | | |
1006 | 1027 | | |
1007 | 1028 | | |
1008 | | - | |
1009 | | - | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
1010 | 1036 | | |
1011 | 1037 | | |
1012 | 1038 | | |
1013 | | - | |
| 1039 | + | |
1014 | 1040 | | |
1015 | 1041 | | |
1016 | 1042 | | |
| |||
1127 | 1153 | | |
1128 | 1154 | | |
1129 | 1155 | | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
1146 | 1159 | | |
1147 | 1160 | | |
1148 | 1161 | | |
| |||
1203 | 1216 | | |
1204 | 1217 | | |
1205 | 1218 | | |
1206 | | - | |
1207 | | - | |
1208 | | - | |
1209 | | - | |
| 1219 | + | |
| 1220 | + | |
1210 | 1221 | | |
1211 | 1222 | | |
1212 | 1223 | | |
| |||
1940 | 1951 | | |
1941 | 1952 | | |
1942 | 1953 | | |
1943 | | - | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
1944 | 1963 | | |
1945 | 1964 | | |
1946 | 1965 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2727 | 2727 | | |
2728 | 2728 | | |
2729 | 2729 | | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
2730 | 2794 | | |
2731 | 2795 | | |
2732 | 2796 | | |
| |||
0 commit comments