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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions numpy/_core/numerictypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,15 @@ def issubdtype(arg1, arg2):
True

"""
if not issubclass_(arg1, generic):
arg1 = dtype(arg1).type
if not issubclass_(arg2, generic):
arg2 = dtype(arg2).type
try:
if not issubclass_(arg1, generic):
arg1 = dtype(arg1).type
if not issubclass_(arg2, generic):
arg2 = dtype(arg2).type
except TypeError:
# If either arg1 or arg2 cannot be casted to dtype object,
# they are not subdtype. (See #-28946)
return False

return issubclass(arg1, arg2)

Expand Down
4 changes: 4 additions & 0 deletions numpy/_core/tests/test_numerictypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ def test_nondtype_nonscalartype(self):
assert not np.issubdtype(np.float32, "float")
assert not np.issubdtype(np.float64, "f")

# Some type cannot be interpreted by numpy
assert not np.issubdtype(str | int, np.number)
assert not np.issubdtype(np.number, str | int | float)

# Test the same for the correct first datatype and abstract one
# in the case of int, float, complex:
assert np.issubdtype(np.float64, 'float64')
Expand Down
Loading
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