Skip to content

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

Closed

Description

@Zac-HD
>>> 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.

Activity

  1. Zac-HD commented on Aug 22, 2021

    @Zac-HD
    ContributorAuthor

    @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...

  2. seberg commented on Mar 14, 2023

    @seberg
    Member

    Closed by gh-23295

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions