Skip to content

BUG: Avoid TypeError in numpy.issubdtype when uninterpretable input… #29451

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

Closed

Conversation

riku-sakamoto
Copy link
Contributor

Overview

Add try-except guard in numpy.issubdtype.

Details

… type

As reported in numpy#28946, `numpy.issubdtype` raises TypeError
when given uninterpretable type. This commit adds try-except guard
to handle such cases.
@riku-sakamoto riku-sakamoto force-pushed the fix_subdtype_raise_typeerror branch from db6a300 to 70e9e2c Compare July 26, 2025 14:07
@riku-sakamoto riku-sakamoto marked this pull request as ready for review July 26, 2025 14:33
@jorenham
Copy link
Member

This (implicitly) changes the type signature of issubdtype to (arg1: object, arg2: object) -> bool. And I'm sure you see why I (a static typing nerd) don't really like that haha.

But on a more serious note, this will cause np.issubdtype(np.int8 | np.uint8, np.integer) to return False. If we ever decide to implement support for such types.UnionType input (e.g. by simply using typing.get_args()), then that the result would change to True. But that is backwards incompatible. So the consequence of this PR, is that we are no longer able to implement support for UnionType, or any other extensions to the allowed input types. So this PR is effectively puts issubdtype into feature-permafrost. This also means that if we ever were to add a new dtype or scalar type, it would be backwards- and forwards-incompatible for issubdtype.

@riku-sakamoto
Copy link
Contributor Author

@jorenham

Thank you for your comment! Your concerns make perfect sense.

As you pointed out, this change breaks the type signature and removes the possibility of future extensions.
I'm planning to close this PR once @seberg also agrees.

In any case, I really appreciate your detailed feedback. I learned a lot from your review. Thanks!

@seberg
Copy link
Member

seberg commented Jul 28, 2025

Yeah, I agree, not much point in doing this and it may be confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy