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

fix: build proper mask in unproject_layout #473

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/dask_awkward/lib/unproject_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,15 @@ def _unproject_layout(form, layout, length, backend):
# UnmaskedArray, non-UnmaskedArray form
elif isinstance(layout, UnmaskedArray) and form.is_option:
if isinstance(form, BitMaskedForm):
byte_length = (
unknown_length if length is unknown_length else math.ceil(length / 8.0)
)
return BitMaskedArray(
ak.index.IndexU8.zeros(length, backend.index_nplike),
ak.index.Index(
backend.index_nplike.full(byte_length, 255, dtype=np.uint8)
if form.valid_when
else backend.index_nplike.zeros(byte_length, dtype=np.uint8)
),
_unproject_layout(
form.content, layout.content, layout.content.length, backend
),
Expand All @@ -328,7 +335,11 @@ def _unproject_layout(form, layout, length, backend):
)
elif isinstance(form, ByteMaskedForm):
return ByteMaskedArray(
ak.index.Index8.zeros(length, backend.index_nplike),
ak.index.Index(
backend.index_nplike.full(length, 1, dtype=np.int8)
if form.valid_when
else backend.index_nplike.zeros(length, dtype=np.int8)
),
_unproject_layout(
form.content, layout.content, layout.content.length, backend
),
Expand Down
21 changes: 21 additions & 0 deletions tests/test_unproject_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,24 @@ def test_UnionArray():
projected = ak.from_iter([{"x": 1}, {"x": 2}, {"x": 3}], highlevel=False)
unprojected = unproject_layout(form, projected)
compare_values(projected, unprojected)


def test_BitMaskedArray():
form = ak.forms.BitMaskedForm('u8', ak.forms.NumpyForm('int64'), valid_when=False, lsb_order=True)
projected = ak.contents.UnmaskedArray(ak.from_iter([1, 2, 3, 4], highlevel=False))
unprojected = unproject_layout(form, projected)
compare_values(projected, unprojected)

form = ak.forms.BitMaskedForm('u8', ak.forms.NumpyForm('int64'), valid_when=True, lsb_order=True)
unprojected = unproject_layout(form, projected)
compare_values(projected, unprojected)

def test_ByteMaskedArray():
form = ak.forms.ByteMaskedForm('u8', ak.forms.NumpyForm('int64'), valid_when=False)
projected = ak.contents.UnmaskedArray(ak.from_iter([1, 2, 3, 4], highlevel=False))
unprojected = unproject_layout(form, projected)
compare_values(projected, unprojected)

form = ak.forms.ByteMaskedForm('u8', ak.forms.NumpyForm('int64'), valid_when=True)
unprojected = unproject_layout(form, projected)
compare_values(projected, unprojected)
Loading