From 6a9c6919c998f85fd3cd9137a3e4903a6acedd49 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Mon, 26 Feb 2024 13:57:26 +0000 Subject: [PATCH] fix: `ak.flatten` on `BitMaskedArray` (#3034) --- src/awkward/contents/bitmaskedarray.py | 2 +- tests/test_3033_flatten_bitmaskedarray.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/test_3033_flatten_bitmaskedarray.py diff --git a/src/awkward/contents/bitmaskedarray.py b/src/awkward/contents/bitmaskedarray.py index c8709255ab..64fa969494 100644 --- a/src/awkward/contents/bitmaskedarray.py +++ b/src/awkward/contents/bitmaskedarray.py @@ -570,7 +570,7 @@ def project(self, mask=None): return self.to_ByteMaskedArray().project(mask) def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content]: - return self.to_ByteMaskedArray._offsets_and_flattened(axis, depth) + return self.to_ByteMaskedArray()._offsets_and_flattened(axis, depth) def _mergeable_next(self, other: Content, mergebool: bool) -> bool: # Is the other content is an identity, or a union? diff --git a/tests/test_3033_flatten_bitmaskedarray.py b/tests/test_3033_flatten_bitmaskedarray.py new file mode 100644 index 0000000000..99a05d347e --- /dev/null +++ b/tests/test_3033_flatten_bitmaskedarray.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +import numpy as np + +import awkward as ak + + +def test(): + layout = ak.to_layout([[[1, 2, 3], [4]], None]).to_BitMaskedArray( + valid_when=True, lsb_order=True + ) + result = ak.flatten(layout, axis=1, highlevel=False) + assert result.is_equal_to( + ak.contents.ListOffsetArray( + ak.index.Index64([0, 3, 4]), + ak.contents.NumpyArray(np.array([1, 2, 3, 4], dtype=np.int64)), + ) + )