-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Conversation
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.
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. */ |
There was a problem hiding this comment.
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.
Looks pretty good in general. |
This follows comments from charris.
TestStructured.test_casting now asserts castability or non-castability using numpy.can_cast in addition to doing the casts.
@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; |
There was a problem hiding this comment.
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.
LGTM modulo some nitpicks. I'm going to squash the files and rebase for backport and then close this. Thanks. |
Fixed up in #5480. |
BUG: Fix astype for structured array fields of different byte order.
The offending commit is c53b0e4, which introduced two regressions:
astype
to cast a structured array to one with a different byte order no longer works;This pull request should fix both.
One thing I wasn't sure about is reordering struct fields. In my implementation, the
equiv
,same_kind
, andsafe
rules are now allowed to reorder fields. If that isn't desired, though, it's a pretty easy change.