Skip to content

pandas2df: fast-path nullable Int64/UInt64 columns - #4

Merged
jefferis merged 1 commit into
mainfrom
claude/pandas2df-speedup-fafbseg-217i74
Aug 22, 2026
Merged

pandas2df: fast-path nullable Int64/UInt64 columns#4
jefferis merged 1 commit into
mainfrom
claude/pandas2df-speedup-fafbseg-217i74

Conversation

@jefferis

Copy link
Copy Markdown
Member

reticulate::py_to_r() walks pandas nullable integer extension columns
(Int64/UInt64) cell-by-cell, which is pathologically slow: ~58s for a
327k-row × 12-col synapse frame. This extracts those columns directly to
bit64::integer64 and drops them from the py_to_r() pass, falling back to
py_to_r for any column the fast path declines (fits int32, all-NA).

~24× faster on that frame (58s → 2.5s); output byte-for-byte identical.
Object/datetime column handling and nullable-int NA precision preserved.

Branches off before the "minimal" bundle merge but only touches
R/convert.R + its test, so main's env.R minimal bundle merges cleanly.
Needed on main for the v0.2.0 release (NEWS credits this speedup).

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

reticulate::py_to_r() walks pandas nullable integer extension columns
(dtype Int64/UInt64) cell by cell, which is pathologically slow on the
large id columns that dominate synapse / partner queries (~24x the whole
conversion; ~58s for a 327k-row synapse frame in fafbseg).

Convert those columns up front via the existing string -> bit64 path
(classify_integer_strings, honouring bigint) and filter them out of the
frame handed to py_to_r, then splice them back into their original
column positions. Columns the fast path declines (all-NA) stay in the
py_to_r pass and keep their native R type. Output is unchanged.

Ported from natverse/fafbseg's fix/pandas2df-nullable-int64-speed and
adapted to nat.python's bigint / classify_integer_strings refactor. The
empty-frame check now reads nrow() from the original frame, since an
all-fast frame yields a 0-column res whose nrow() would misreport as 0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DUcpVWK2jMbGn5GkXhWTmz
@jefferis
jefferis merged commit 8cbd6b4 into main Aug 22, 2026
3 checks passed
@jefferis
jefferis deleted the claude/pandas2df-speedup-fafbseg-217i74 branch August 22, 2026 15:51
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.

2 participants