Skip to content

BUG: Change dtype comparison in _view_is_safe to be independent of name fields. #13261

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
wants to merge 1 commit into from
Closed
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
20 changes: 20 additions & 0 deletions numpy/core/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,27 @@ def _view_is_safe(oldtype, newtype):
"""

# if the types are equivalent, there is no problem.
# compare irrespective of name fields
# for example: dtype((np.record, 'i4,i4')) == dtype((np.void, 'i4,i4'))
def _recursive_remove_name_fields(ndtype):
newdtype = []
if ndtype.names:
for name in ndtype.names:
current = ndtype[name]
if current.names:
newdtype.append(
('', _recursive_remove_name_fields(current))
)
else:
newdtype.append(('', current))
else:
return ndtype.type
return newdtype

if oldtype.names or oldtype.names:
Copy link
Member

Choose a reason for hiding this comment

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

Typo, one of these should say newtype.

Should also use .names is not None here and above.

oldtype = dtype(_recursive_remove_name_fields(oldtype))
newtype = dtype(_recursive_remove_name_fields(newtype))

if oldtype == newtype:
return

Expand Down