コード例 #1
0
def test():
    arr1 = ak.Array({"a": [1, 2], "b": [1, None]})
    arr2 = ak.mask(arr1, [True, True])
    assert isinstance(arr2.layout, ak.layout.ByteMaskedArray)
    assert isinstance(arr2.layout.content, ak.layout.RecordArray)
    assert isinstance(arr2.layout.content.field("b"),
                      ak.layout.IndexedOptionArray64)

    assert isinstance(arr2.b.layout, ak.layout.IndexedOptionArray64)
    assert isinstance(arr2.b.layout.content, ak.layout.NumpyArray)

    assert ak.is_none(arr2.b).tolist() == [False, True]

    arr3 = ak.virtual(lambda: arr2, form=arr2.layout.form, length=len(arr2))
    assert ak.is_none(arr3.b).tolist() == [False, True]
コード例 #2
0
 def get_vpt(check_offshell=False):
     """Only the leptonic samples have no resonance in the decay tree, and only
     when M is beyond the configured Breit-Wigner cutoff (usually 15*width)
     """
     boson = ak.firsts(
         genpart[((genpart.pdgId == 23) | (abs(genpart.pdgId) == 24))
                 & genpart.hasFlags(["fromHardProcess", "isLastCopy"])])
     if check_offshell:
         offshell = genpart[
             genpart.hasFlags(["fromHardProcess", "isLastCopy"])
             & ak.is_none(boson)
             & (abs(genpart.pdgId) >= 11) &
             (abs(genpart.pdgId) <= 16)].sum()
         return ak.where(ak.is_none(boson.pt), offshell.pt, boson.pt)
     return np.array(ak.fill_none(boson.pt, 0.))
コード例 #3
0
def test():
    index_of_index = ak.Array(
        ak.layout.IndexedOptionArray64(
            ak.layout.Index64(np.r_[0, 1, 2, -1]),
            ak.layout.IndexedOptionArray64(
                ak.layout.Index64(np.r_[0, -1, 2, 3]),
                ak.layout.NumpyArray(np.r_[1, 2, 3, 4]),
            ),
        ))

    mask = ak.is_none(index_of_index)
    assert ak.to_list(mask) == [False, True, False, True]
コード例 #4
0
def test():
    assert ak.is_none(ak.Array([1, 2, 3, None, 5])).tolist() == [
        False,
        False,
        False,
        True,
        False,
    ]
    assert ak.is_none(ak.Array([[1, 2, 3], [], [None, 5]])).tolist() == [
        False,
        False,
        False,
    ]
    assert ak.is_none(ak.Array([[1, 2, 3], [], [None, 5]]),
                      axis=1).tolist() == [
                          [False, False, False],
                          [],
                          [True, False],
                      ]
    assert ak.is_none(ak.Array([[1, None, 2, 3], [], [None, 5]]),
                      axis=1).tolist() == [
                          [False, True, False, False],
                          [],
                          [True, False],
                      ]
    assert ak.is_none(ak.Array([[1, None, 2, 3], [], [None, 5]]),
                      axis=-1).tolist() == [
                          [False, True, False, False],
                          [],
                          [True, False],
                      ]
    assert ak.is_none(ak.Array([[1, None, 2, 3], [], [None, 5]]),
                      axis=-2).tolist() == [
                          False,
                          False,
                          False,
                      ]
    assert ak.is_none(ak.Array([[1, None, 2, 3], None, [None, 5]]),
                      axis=-2).tolist() == [False, True, False]
    with pytest.raises(ValueError):
        ak.is_none(ak.Array([[1, None, 2, 3], [], [None, 5]]), axis=-3)
コード例 #5
0
def test_na_union():
    one = ak.from_iter([1, None, 3], highlevel=False)
    two = ak.from_iter([[], [1], None, [3, 3, 3]], highlevel=False)
    tags = ak.layout.Index8(np.array([0, 1, 1, 0, 0, 1, 1], dtype=np.int8))
    index = ak.layout.Index64(np.array([0, 0, 1, 1, 2, 2, 3], dtype=np.int64))
    array = ak.Array(ak.layout.UnionArray8_64(tags, index, [one, two]),
                     check_valid=True)
    assert ak.to_list(array) == [1, [], [1], None, 3, None, [3, 3, 3]]

    assert ak.to_list(ak.is_none(array)) == [
        False,
        False,
        False,
        True,
        False,
        True,
        False,
    ]
コード例 #6
0
 def num(ar):
     return ak.num(ak.fill_none(ar[~ak.is_none(ar)], 0), axis=0)
コード例 #7
0
 def skim_weight(arr):
     mask1 = ~ak.is_none(arr)
     subarr = arr[mask1]
     mask2 = subarr != 0
     return ak.to_numpy(subarr[mask2])
コード例 #8
0
def test_numpy_array():
    x = np.arange(12)
    y = ak.is_none(x)

    assert y.tolist() == [False] * 12
コード例 #9
0
def test_awkward_from_numpy_array():
    x = np.arange(12)
    y = ak.from_numpy(x)
    z = ak.is_none(y)

    assert z.tolist() == [False] * 12