pandas2df: fast-path nullable Int64/UInt64 columns - #4
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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