File: test_1259_simplify_optiontype.py

package info (click to toggle)
python-awkward 2.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 23,088 kB
  • sloc: python: 148,689; cpp: 33,562; sh: 432; makefile: 21; javascript: 8
file content (38 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import numpy as np
import pytest  # noqa: F401

import awkward as ak


def test_byte_masked_array():
    layout = ak.contents.ByteMaskedArray.simplified(
        ak.index.Index8(np.r_[0, 1, 1]),
        ak.contents.IndexedOptionArray(
            ak.index.Index64([0, 1, -1]), ak.contents.NumpyArray(np.arange(3))
        ),
        valid_when=True,
    )
    assert layout.to_list() == [None, 1, None]

    assert isinstance(layout, ak.contents.IndexedOptionArray)
    assert np.asarray(layout.index).tolist() == [-1, 1, -1]


def test_bit_masked_array():
    layout = ak.contents.BitMaskedArray.simplified(
        ak.index.IndexU8(np.array([0 | 1 << 1 | 1 << 2], dtype=np.uint8)),
        ak.contents.IndexedOptionArray(
            ak.index.Index64([0, 1, -1]), ak.contents.NumpyArray(np.arange(3))
        ),
        valid_when=True,
        length=3,
        lsb_order=True,
    )
    assert layout.to_list() == [None, 1, None]

    assert isinstance(layout, ak.contents.IndexedOptionArray)
    assert np.asarray(layout.index).tolist() == [-1, 1, -1]