-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
ENH: Add future.python_scalars #63016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rhshadrach
wants to merge
5
commits into
pandas-dev:main
Choose a base branch
from
rhshadrach:enh_python_scalars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+256
−87
Conversation
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
Member
Author
Member
Member
Author
Plan to run a full set of ASVs next week, some microbenchmarks from pandas.core.dtypes.cast import maybe_unbox_numpy_scalar
with pd.option_context("python_scalars", True):
%timeit maybe_unbox_numpy_scalar(np.int64(2))
# 828 ns ± 9.91 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
%timeit maybe_unbox_numpy_scalar(2)
# 161 ns ± 0.414 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
ser = pd.Series([1, 2, 3] * 10_000)
with pd.option_context("python_scalars", True):
%timeit ser.sum()
# 9.42 μs ± 423 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
with pd.option_context("python_scalars", False):
%timeit ser.sum()
# 8.28 μs ± 137 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each) |
1 task
Dr-Irv
reviewed
Nov 10, 2025
Member
Author
|
Full ASVs are below, only showing where there was a 10% of more regression. In the full list, only the following two actually hit the function Full listI was curious why only min/max showed up as being regressions in series_methods.NanOps |
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.
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.Adds an experimental option to return Python scalars instead of NumPy scalars across the API. This is not yet fully implemented everywhere, e.g.
Series.__getitem__, but I'm hoping reductions are a substantial chunk.This is complicated by #62988 where it was found that many of our doctests are not running. We run those doctests using NumPy>=2, and if we were to get those doctests to pass as-is, we would need to change the NumPy reprs from e.g.
2tonp.int64(2). If we then change reductions et al to returning Python scalars, we'd then change all the reprs back from e.g.np.int64(2)to2. So instead I think we can:future.python_scalarstoTruein 4.0, deprecate the future option.