Skip to content

Missing byteswap when converting array with record dtype to opposite-endian dtype. #6314

Closed

Description

@mdickinson

Consider the following self-contained snippet of code:

import numpy as np
dtype = np.dtype([("V", "<f8"), ("A", "<f8")])
be_dtype = dtype.newbyteorder('>')
value = np.array((1.1, 1.2), dtype=dtype)

print np.asarray(value, dtype=be_dtype)
print np.asarray([value], dtype=be_dtype)

When I run this under Python 2.7 and NumPy 1.9.2 on my OS X 10.9 machine, I get the following output:

(1.1, 1.2)
[(-1.5423487136706484e-180, 4.667261458438315e-62)]

I'd expect to get this output:

(1.1, 1.2)
[(1.1, 1.2)]

Doing the same with a scalar dtype gives me the expected behaviour, and replacing value with the tuple (1.1, 1.2) also gives me the expected behaviour. It looks as though there's a byteswap operation being missed at some level during the conversion.

Activity

  1. ahaldane commented on Sep 14, 2015

    @ahaldane
    Member

    This happens because VOID_setitem copies structured arrays as if they were void buffers, so no casting or byteswapping occurs. For example try this:

    print array([value], dtype=[("V", "i8"), ("A", "i8")])
    

    This would be fixed by #6053

  2. added 3 commits that reference this issue on Jun 17, 2016
    2ef0103
  3. added a commit that references this issue on Oct 23, 2017
    ae582a8
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