Skip to content
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

Confusing ndarray repr: always shows dtype as if in native byteorder #19059

Closed
Zac-HD opened this issue May 21, 2021 · 2 comments
Closed

Confusing ndarray repr: always shows dtype as if in native byteorder #19059

Zac-HD opened this issue May 21, 2021 · 2 comments

Comments

@Zac-HD
Copy link
Contributor

Zac-HD commented May 21, 2021

>>> from numpy import array, dtype

# The repr of a dtype object distinguishes non-native byteorder.
>>> dtype('<u2')
dtype('uint16')
>>> dtype('>u2')
dtype('>u2')

# But arrays always use the repr of the native endianness
>>> array([0], dtype='<u2')
array([0], dtype=uint16)
>>> array([0], dtype='>u2')
array([0], dtype=uint16)  #   <-- this is confusing

This isn't strictly speaking a bug, but using the byteorder-sensitive repr of the dtype instead would make it easier to tell when you have an endianness issue in e.g. this StackOverflow question.

@Zac-HD
Copy link
Contributor Author

Zac-HD commented Aug 22, 2021

@mattip - any tips on where I should be looking to fix this?

Twenty minutes with grep and examining various __repr__-related code snippets didn't get me anywhere, though I can see from https://github.com/numpy/numpy/blob/main/numpy/core/_dtype.py that it might be tricky if I can't simply have the array repr defer to the dtype repr...

@seberg
Copy link
Member

seberg commented Mar 14, 2023

Closed by gh-23295

@seberg seberg closed this as completed Mar 14, 2023
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

No branches or pull requests

2 participants