Skip to content

fix(tl): sliding_window overlap columns as bool, not object - #1327

Open
selmanozleyen wants to merge 3 commits into
scverse:mainfrom
selmanozleyen:fix/sliding-window-bool-columns
Open

selmanozleyen wants to merge 3 commits into
scverse:mainfrom
selmanozleyen:fix/sliding-window-bool-columns

Conversation

@selmanozleyen

@selmanozleyen selmanozleyen commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

With overlap > 0, tl.sliding_window writes one membership column per window. Each column is built by a .loc enlargement that sets True on the window's cells and leaves NaN elsewhere. That makes an object column, and fillna(False) keeps it object. So users get object columns of Python bools rather than bool columns: about 8× the memory per column, and slower reductions over many windows.

sq.tl.sliding_window(adata, window_size=w, overlap=w // 2)
adata.obs["sliding_window_assignment_window_0"].dtype  # object on main, bool with this PR

Fix: .astype(bool) after the fillna. The window assignments are unchanged; only the dtype differs. The existing overlap test now asserts bool (it fails on main, passes here).

Found while benchmarking: comparing outputs across branches flagged the overlap columns as different, and the difference turned out to be only their dtype.

With overlap > 0, each window column is built by a .loc enlargement that sets True on the window's cells and leaves NaN elsewhere, an object column; fillna(False) keeps it object. Cast to bool, and assert the dtype in the existing overlap test.
@selmanozleyen
selmanozleyen force-pushed the fix/sliding-window-bool-columns branch from b6fc514 to e5296c9 Compare October 27, 2026 20:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant