Skip to content

fix(types): update NDArray[object] to be NDArray[numpy.object_] #5571

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

Merged
merged 3 commits into from
Mar 21, 2025

Conversation

InvincibleRMC
Copy link
Contributor

@InvincibleRMC InvincibleRMC commented Mar 18, 2025

Description

Use proper numpy.object_ type instead of default object type.

Suggested changelog entry:

Use ``numpy.object_`` instead of ``object``

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@timohl could you please help reviewing this tiny PR?

Copy link
Contributor

@timohl timohl left a comment

Choose a reason for hiding this comment

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

I think it makes not much difference changing this, but I am ok with it.

There are no clear guidelines.
Some references I found:

The third column lists alternative NumPy names which may occasionally be preferential.

To give a clear guideline for the vast majority of cases, for the types bool, object, str (and unicode) using the plain version is shorter and clear, and generally a good replacement.

@InvincibleRMC please correct me, if I am missing anything, making this PR is strictly preferable?

@InvincibleRMC
Copy link
Contributor Author

Yeah I believe numpy.object_ is strictly preferable. Running mypy on the plain object version had it complaining that it did not inherit from np.generic.

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Thanks @timohl for the review!
Thanks @InvincibleRMC!

@rwgk rwgk merged commit 6412615 into pybind:master Mar 21, 2025
80 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Mar 21, 2025
@henryiii henryiii changed the title Update NDArray[object] to be NDArray[numpy.object_] fix(types): update NDArray[object] to be NDArray[numpy.object_] Mar 31, 2025
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Apr 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants