Repository navigation
BUG: DataFrame.apply(raw=True) casting scalar results to the first result's dtype (GH#61632) - #71958
Merged
Merged
Conversation
…sult's dtype (GH#61632) Scalar results now infer their dtype from all results, as with raw=False, instead of being cast to the dtype of the first, e.g. 1 followed by 2.5 gave 2. List-like results keep the first-result buffer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jbrockmendel
force-pushed
the
bug-61632
branch
from
November 9, 2026 03:01
a229138 to
40b2197
Compare
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.
Depends on GH-71926.
DataFrame.apply(raw=True)cast scalar results to the dtype of the first one (GH-61632), so1followed by2.5gave[1, 2, 2, 2], and1followed bynangave[1, 0, 0, 0]. The dtype is now inferred from all results, as withraw=False. The docstring note added in GH-62384 is narrowed to list-like results.List-like results keep the first-result dtype, so
x if cond else x / 2still truncates. Stacking withnp.array(results)would fix that but corruptsdatetime64[ns]mixed with float arrays into epoch ints, dropsMaskedArraymasks, and breaks funcs that reuse their output array.Other behavior changes:
bytesresults give an object Series instead ofS3.Nonefollowed by ints gives float64 withNaNinstead of object.Scalar funcs also get faster: 1.65-2.5x against main, up from 1.25-1.4x with GH-71926 alone.
AI disclosure: drafted with Claude Code (
claude opus 5.5 (high)), used for the investigation, implementation, and iterative review of the branch.🤖 Generated with Claude Code