Skip to content
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

unexpected behaviour of ak.where with arrays containing Nones #3098

Open
maadcoen opened this issue May 2, 2024 · 0 comments
Open

unexpected behaviour of ak.where with arrays containing Nones #3098

maadcoen opened this issue May 2, 2024 · 0 comments
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged

Comments

@maadcoen
Copy link

maadcoen commented May 2, 2024

Version of Awkward Array

1.10.5

Description and code to reproduce

I ran into this weird behaviour of ak.where when used on arrays of mixed datatype (not sure about the terminology, but I mean arrays potentially containing None values, as indicated by the question mark).

Basically, the function breaks down when the boolean condition is of mixed datatype and the choices contain a None value.
In that case, the output will be None, even when the boolean condition doesn't contain any Nones at all and the None value shouldn't have been selected. For the choice arrays, the problem only arises when one of them contains a None indeed. For the boolean arrays, it is sufficient that the datatype is mixed.
See the code below to reproduce this behaviour.

mixed_type_cond = ak.Array([[True], [None]])[0]
pure_type_cond = ak.Array([True])
none_alternative = ak.Array([None])
zero_alternative = ak.Array([0])
mixed_zero_alternative = ak.Array([[0], [None]])[0]

ak.where(mixed_type_cond, 1, none_alternative)
>>> <Array [None] type='1 * ?int64'>
ak.where(mixed_type_cond, 1, zero_alternative)
>>> <Array [1] type='1 * ?int64'>
ak.where(mixed_type_cond, 1, mixed_zero_alternative)
>>> <Array [1] type='1 * ?int64'>

ak.where(pure_type_cond, 1, none_alternative)
>>> <Array [1] type='1 * ?int64'>
ak.where(pure_type_cond, 1, zero_alternative)
>>> <Array [1] type='1 * ?int64'>
ak.where(pure_type_cond, 1, mixed_zero_alternative)
>>> <Array [1] type='1 * ?int64'>

ak.where(~mixed_type_cond, none_alternative, 1)
>>> <Array [None] type='1 * ?int64'>
ak.where(~mixed_type_cond, zero_alternative, 1)
>>> <Array [1] type='1 * ?int64'>
ak.where(~mixed_type_cond, mixed_zero_alternative, 1)
>>> <Array [1] type='1 * ?int64'>
@maadcoen maadcoen added the bug (unverified) The problem described would be a bug, but needs to be triaged label May 2, 2024
@jpivarski jpivarski added this to P1 (highest) in Finalization May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged
Projects
Finalization
P1 (highest)
Development

No branches or pull requests

1 participant