Skip to content

[numpy] Fix breakage in users of Python protobufs under NumPy 2.3rc1.#22171

Merged
mkruskal-google merged 1 commit into29.xfrom
numpy-fix-29
Jun 10, 2025
Merged

[numpy] Fix breakage in users of Python protobufs under NumPy 2.3rc1.#22171
mkruskal-google merged 1 commit into29.xfrom
numpy-fix-29

Conversation

@mkruskal-google
Copy link
Member

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

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
@mkruskal-google mkruskal-google requested a review from a team as a code owner June 9, 2025 22:12
@mkruskal-google mkruskal-google added the back-port Cherrypick PRs to release branches label Jun 9, 2025
@mkruskal-google mkruskal-google requested review from haberman and removed request for a team June 9, 2025 22:12
@mkruskal-google mkruskal-google merged commit c6c8a17 into 29.x Jun 10, 2025
199 checks passed
@mkruskal-google mkruskal-google deleted the numpy-fix-29 branch June 10, 2025 03:59
Copy link

@noelportillo noelportillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the bests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

back-port Cherrypick PRs to release branches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants