[numpy] Fix breakage in users of Python protobufs under NumPy 2.3rc1.#22171
Merged
mkruskal-google merged 1 commit into29.xfrom Jun 10, 2025
Merged
[numpy] Fix breakage in users of Python protobufs under NumPy 2.3rc1.#22171mkruskal-google merged 1 commit into29.xfrom
mkruskal-google merged 1 commit into29.xfrom
Conversation
As of NumPy 2.3.0rc1, numpy.bool scalars can no longer be interpreted as index values (https://github.com/numpy/numpy/releases/tag/v2.3.0rc1). This causes protobuf no longer to accept a np.bool scalar as a legal value for a boolean field. We have two options: a) either we can change protobuf so that it continues to accept NumPy boolean scalars (this change), or b) decide that protobuf should reject NumPy boolean scalars and that users must update their code to cast to a Python bool explicitly. I have no strong opinion as to which, but option (a) seems less disruptive. No test updates are needed: the existing tests fail under NumPy 2.3. PiperOrigin-RevId: 766629310
haberman
approved these changes
Jun 10, 2025
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.
As of NumPy 2.3.0rc1, numpy.bool scalars can no longer be interpreted as index values (https://github.com/numpy/numpy/releases/tag/v2.3.0rc1). This causes protobuf no longer to accept a np.bool scalar as a legal value for a boolean field.
We have two options:
a) either we can change protobuf so that it continues to accept NumPy boolean scalars (this change), or b) decide that protobuf should reject NumPy boolean scalars and that users must update their code to cast to a Python bool explicitly.
I have no strong opinion as to which, but option (a) seems less disruptive.
No test updates are needed: the existing tests fail under NumPy 2.3.
PiperOrigin-RevId: 766629310