-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DEP,BUG: Coercion/cast of array to a subarray dtype will be fixed #17596
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
760be52
to
81b8611
Compare
@@ -314,6 +314,23 @@ def test_union_struct(self): | |||
'formats':['i1', 'O'], | |||
'offsets':[np.dtype('intp').itemsize, 0]}) | |||
|
|||
@pytest.mark.parametrize(["obj", "dtype", "expected"], | |||
[(3, "(3)f4,", [3, 3, 3]), | |||
(np.float64(2), "(2)f4,", [2, 2]), |
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.
To be clear, the first case here previously returned [3, uninitialized, uninitialized]
, while the second case actually did the right thing. So I considered that a simple bugfix here.
@seberg - this looks quite good. With this change, will |
This currently appends the subarray dtype dimensions first and then tries to assign to the result array which uses incorrect broadcasting (broadcasting against the subarray dimensions instead of repeating each element according to the subarray dimensions). This also fixes the python scalar pathway `np.array(2, dtype="(2)f4,")` which previously only filled the first value. I consider that a clear bug fix. Closes numpygh-17511
22a10b1
to
fcc3940
Compare
Thanks for taking a look! I am scanning the full input for array(-like) objects in the code, it is a bit annoying, but feel this is fringe enough that it is OK. Since I look for array likes, it will not trigger for empty sequences. There are cases where a warning will be given even though nothing will change, e.g. |
OK, that sounds good! And I can see that you cannot do everything... But perhaps good to add a test for the empty list case, just in case? |
Oh, seems I accidentally deleted that sentence snippet: I had just added the test. |
Thanks @seberg |
This currently appends the subarray dtype dimensions first and then
tries to assign to the result array which uses incorrect broadcasting
(broadcasting against the subarray dimensions instead of repeating
each element according to the subarray dimensions).
This also fixes the python scalar pathway
np.array(2, dtype="(2)f4,")
which previously only filled the first value. I consider that a clear
bug fix.
Closes gh-17511