Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: Comparison operator for subarrays is wrong/unimplemented #10442

Closed
@ahaldane

Description

@ahaldane

Currently, sorting and comparison of subarrays is wrong in many cases.

This was discovered because trying to sort arrays with subarrays leads to different results on little-endian systems vs big-endian:

>>> z = np.array([([3,3],), ([-1,0],)], dtype=[('v', '>i4', (2,))])
>>> z[0] < z[1]

On little endian, the last line returns True. On big-endian, it returns False.

Here's what's happening: In VOID_compare, this line, see that non-structured voids are compared by doing cmp(val1.tobytes(), val2.tobytes(). In other words, it looks like we treat subarrays as if they were plain 'np.void' types and use a simple string compare. That's why endianness mattered, but it also means that a lot of other cases are wrong since we are comparing the byte values rather than the numerical values.

I think we need to add an extra block there to take care of subarrays.

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