Skip to content

BUG: astype is broken for structured arrays with different byte orders #5279

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 8 commits into from
Closed

BUG: astype is broken for structured arrays with different byte orders #5279

wants to merge 8 commits into from

Conversation

dranjan
Copy link

@dranjan dranjan commented Nov 14, 2014

The offending commit is c53b0e4, which introduced two regressions:

  • using astype to cast a structured array to one with a different byte order no longer works;
  • comparing structured-array dtypes can give incorrect results if the two dtypes have different byte orders.

This pull request should fix both.

One thing I wasn't sure about is reordering struct fields. In my implementation, the equiv, same_kind, and safe rules are now allowed to reorder fields. If that isn't desired, though, it's a pretty easy change.

Darsh P. Ranjan added 3 commits November 12, 2014 10:03
The behavior of _equivalent_fields has been reverted to avoid breaking
astype for structured arrays.
The logic for determining whether one structured dtype can be cast to
another has been rewritten, enabling some casts that raised TypeError
before.  Specifically, 'equiv', 'safe', and 'same_kind' casting are now
possible.

This incidentally restores equality comparison for structured arrays,
which I just broke in a previous commit.
@dranjan
Copy link
Author

dranjan commented Nov 14, 2014

Oops, it looks like some of my tests break under Python 2.6... :-(

(subsequently fixed)

Apparently this functionality wasn't available in Python 2.6.
@@ -624,6 +624,43 @@ type_num_unsigned_to_signed(int type_num)
}
}

/* Compare two field dictionaries for castability. */
Copy link
Member

Choose a reason for hiding this comment

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

Please document the function in more detail, in particular the meaning of the return values. Is 0 an error return? Error flags are usually negative.

@charris
Copy link
Member

charris commented Nov 20, 2014

Looks pretty good in general.

Darsh Ranjan added 4 commits December 6, 2014 15:43
This follows comments from charris.
TestStructured.test_casting now asserts castability or non-castability
using numpy.can_cast in addition to doing the casts.
@dranjan
Copy link
Author

dranjan commented Dec 7, 2014

@charris - thanks for reviewing this, and sorry for taking so long (I've been AFK a lot for the past couple weeks). I think I addressed all the issues you brought up. I also slightly expanded my tests, so hopefully that was all right.

{
Py_ssize_t ppos;
PyObject *key;
PyObject *tuple1, *tuple2;
Copy link
Member

Choose a reason for hiding this comment

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

Should probably initialize these to NULL to avoid compiler warnings.

@charris charris added this to the 1.9.2 milestone Jan 22, 2015
@charris
Copy link
Member

charris commented Jan 22, 2015

LGTM modulo some nitpicks. I'm going to squash the files and rebase for backport and then close this. Thanks.

@charris
Copy link
Member

charris commented Jan 22, 2015

Fixed up in #5480.

@charris charris closed this Jan 22, 2015
charris referenced this pull request Jan 22, 2015
BUG: Fix astype for structured array fields of different byte order.
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

Successfully merging this pull request may close these issues.

2 participants