File: test_0992_correct_ptp_unmasking.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 (85 lines) | stat: -rw-r--r-- 1,838 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import numpy as np  # noqa: F401
import pytest  # noqa: F401

import awkward as ak


def test():
    array = ak.highlevel.Array(
        [
            [0, 1, None],
            [None, 3],
            [],
            None,
            [4, 5, None, 6],
        ]
    )

    assert ak.operations.sum(array, axis=-1).to_list() == [
        1,  # 0 + 1
        3,  # 3
        0,  # list is empty
        None,  # list is missing
        15,  # 4 + 5 + 6
    ]

    assert ak.operations.sum(array, axis=-2).to_list() == [
        4,
        9,
        0,
        6,
        # 0+4
        #     1+3+5
        #         no data
        #                     6
    ]

    assert ak.operations.min(array, axis=-1).to_list() == [
        0,  # min([0, 1])
        3,  # min([3])
        None,  # list is empty
        None,  # list is missing
        4,  # min([4, 5, 6])
    ]

    assert ak.operations.min(array, axis=-2).to_list() == [
        0,
        1,
        None,
        6,
        # 0,4
        #     1,3,5
        #          no data
        #                     6
    ]

    # first bug-fix: single '?'
    assert str(ak.operations.min(array, axis=-1).type) == "5 * ?int64"

    # second bug-fix: correct mask_identity=False behavior
    assert ak.operations.ptp(array, axis=-1).to_list() == [
        1,
        0,
        None,
        None,
        2,
    ]
    assert ak.operations.ptp(array, axis=-1, mask_identity=False).to_list() == [
        1,
        0,
        0,
        None,
        2,
    ]

    assert ak.operations.ptp(array, axis=-2).to_list() == [4, 4, None, 0]
    assert ak.operations.ptp(array, axis=-2, mask_identity=False).to_list() == [
        4,
        4,
        0,
        0,
    ]