BUG: Raise promotion error if a DType was provided in array coercion#17706
Conversation
921bd0a to
34800ec
Compare
This fixes mainly the creation of unstructured void arrays from scalars, by allowing promotion two unstructured void dtypes. Structured voids will fail promoting. This promotion error is now correctly floated out instead of using `object` dtype which is incorrect when a dtype was passed in.
34800ec to
937e624
Compare
mattip
left a comment
There was a problem hiding this comment.
The code itself looks good, but could use some documentation cleanup
| arr = np.array([b"12345", b"1234"], dtype="V") | ||
| assert arr.dtype == 'V5' | ||
| # Check the same for the casting path: | ||
| arr = np.array([b"1234", b"12345"], dtype="O").astype("V") |
There was a problem hiding this comment.
What does this do? Zero-pad? Undefined-data-pad?
Can you add a test for that?
|
I'm not convinced that allowing promotion of void buffers is sensible - the void type is not null-terminated, so |
|
Hmmpf, that is a good point. The reason for that change was to make the I guess I can make the coercion with |
This means that we effectively remove certain (strange) array coercions for unstructured void datatypes.
|
OK, I change it to that. We can briefly discuss this, but I think this is the reasonable thing to do. A bare |
|
Can we raise an error message that indicates that null padding can be achieved by using bytes instead? |
|
Not really, since this is a promotion error message you would need special handling just for void somewhere... |
|
The code right now seems to give the error "invalid type promotion with structured or void datatype(s)". I'm suggesting we tailor that a bit for different types of void dtypes. Or is your point that the error is swallowed? |
|
Sorry, too much casting :(. For I added the error, it will also show up for other things (although probably not realistically). I guess one thing we could think about is creating a |
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
|
Gentle ping, can we put this in? |
|
Thanks @mattip, its not a big change and it is holding me up a bit, so I will squash merge it in a bit when the test ran through (undid a leftover change from the first version). |
This fixes mainly the creation of unstructured void arrays from
scalars, by allowing promotion two unstructured void dtypes.
Structured voids will fail promoting. This promotion error is
now correctly floated out instead of using
objectdtype whichis incorrect when a dtype was passed in.