You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
astype converts numpy array values to 0.0 for structured dtype #7058
I will check when I get home, but I suspect this is another version of the long-standing bug which could be fixed by #6053. Specifically, I think this is example 'v3' in the example there: When numpy does not find a matching field-name on the lhs, it simply assigns 0 to the rhs field.
I'd also add, @mpconte's example is in some sense the current desired behavior: Assignment between two structures arrays currently works by matching up field names between the lhs and rhs. If a field name on the rhs is not present in the lhs, that field gets assigned 0. This is not documented anywhere, but there are comments in the code suggesting it is intentional.
If you want a real mind-bender, replaced flattened_dtype in your example by
Thanks for the insight.
I also just discovered that using view instead of astype acutally gives me the result I'd expect, regardless of field names, thanks.
Activity
charris commentedon Jan 18, 2016
Also in 1.11.
ahaldane commentedon Jan 18, 2016
I will check when I get home, but I suspect this is another version of the long-standing bug which could be fixed by #6053. Specifically, I think this is example 'v3' in the example there: When numpy does not find a matching field-name on the lhs, it simply assigns 0 to the rhs field.
ahaldane commentedon Jan 18, 2016
I'd also add, @mpconte's example is in some sense the current desired behavior: Assignment between two structures arrays currently works by matching up field names between the lhs and rhs. If a field name on the rhs is not present in the lhs, that field gets assigned 0. This is not documented anywhere, but there are comments in the code suggesting it is intentional.
If you want a real mind-bender, replaced
flattened_dtypein your example bycharris commentedon Jan 18, 2016
That makes sense.
mpconte commentedon Jan 19, 2016
Thanks for the insight.
I also just discovered that using view instead of astype acutally gives me the result I'd expect, regardless of field names, thanks.
MAINT: improve struct assignment, allow multi fields views
6 remaining items
MAINT: improve struct assignment, allow multi fields views