`ByteMaskedArray.mask_as_bool` returns inverted validity for `valid_when=False`
Version of Awkward Array
2.8.10
Description and code to reproduce
mask_as_bool contradicts the documented semantics of ByteMaskedArray. The docs state that elements are valid exactly where mask[i] == valid_when . However, when the array is built with valid_when=False, mask_as_bool() currently returns mask != 0, so valid slots (mask=0) come back as False and invalid slots (mask=1) come back as True. This breaks semantics.
import numpy as np
import awkward as ak
mask = ak.index.Index8(np.array([0, 1], dtype=np.int8))
content = ak.contents.NumpyArray(np.array([10, 20], dtype=np.int64))
layout = ak.contents.ByteMaskedArray(mask, content, valid_when=False)
print(layout.mask_as_bool()) # expected [True, False]
print(layout.mask_as_bool(False))
[False True]
[False True]
Note: This issue was identified by an automated testing tool for academic research and manually verified. If you have any concerns about this type of reporting, please let me know, and I will adjust my workflow accordingly.
@T90REAL - Thanks for reporting this! I can see that you have put a lot of work in testing awkward and reporting the issues. Thank you!
You are welcome to submit the PRs with fixes. Please let us know if you would like to contribute and need help with it. Thank you!
You are welcome to submit the PRs with fixes. Please let us know if you would like to contribute and need help with it. Thank you!
Got it! Also thanks for your response.