Skip to content

Commit a96098c

Browse files
committed
feat(ptm): reindex columns in run_binned_interaction_lmm to enforce sparsity gate
1 parent 48b09db commit a96098c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

hvantk/ptm/test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,14 @@ def _skipped(note: str, bin_levels=None) -> BinnedLMMResult:
272272
dfx["expr_bin"] = pd.Categorical(assigned, categories=ordered, ordered=True)
273273

274274
# Sparsity gate: every (expr_bin, is_ptm) cell must have >= min_cell_n.
275-
bc = dfx.groupby(["expr_bin", "is_ptm"], observed=False).size().unstack(fill_value=0)
275+
# Reindex columns to [0, 1] so strata missing an entire PTM class still
276+
# fail the gate instead of squeezing through on a degenerate design.
277+
bc = (
278+
dfx.groupby(["expr_bin", "is_ptm"], observed=False)
279+
.size()
280+
.unstack(fill_value=0)
281+
.reindex(columns=[0, 1], fill_value=0)
282+
)
276283
if (bc < min_cell_n).any().any():
277284
return _skipped("skipped: sparse bins", bin_levels=ordered)
278285

0 commit comments

Comments
 (0)