File: test_2769_argsort_all_none.py

package info (click to toggle)
python-awkward 2.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,932 kB
  • sloc: python: 178,875; cpp: 33,828; sh: 432; makefile: 21; javascript: 8
file content (53 lines) | stat: -rw-r--r-- 1,573 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
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import pytest  # noqa: F401

import awkward as ak


def test_all_none():
    result = ak.argsort([None, None, None])
    assert ak.is_valid(result)
    assert result.to_list() == [0, 1, 2]
    assert isinstance(result.layout, ak.contents.NumpyArray)
    assert result.type == ak.types.ArrayType(ak.types.NumpyType("int64"), 3)


def test_mixed_none_local():
    result = ak.argsort([None, 1, None, 2, 0, None, -1])
    assert ak.is_valid(result)
    assert result.to_list() == [6, 4, 1, 3, 0, 2, 5]
    assert result.type == ak.types.ArrayType(ak.types.NumpyType("int64"), 7)


def test_mixed_none_2d_local():
    result = ak.argsort(
        [
            [None, 1, None, 0, None, None, -1],
            None,
            [None, 2, None, 2, 0, None, -2],
        ],
        axis=1,
    )
    assert ak.is_valid(result)
    assert result.to_list() == [[6, 3, 1, 0, 2, 4, 5], None, [6, 4, 1, 3, 0, 2, 5]]
    assert result.type == ak.types.ArrayType(
        ak.types.OptionType(ak.types.ListType(ak.types.NumpyType("int64"))), 3
    )


def test_mixed_none_2d_nonlocal():
    result = ak.argsort(
        [
            [None, 1, None, 0, None, None, -1],
            [None, 2, None, 2, 0, None, -2],
        ],
        axis=0,
    )
    assert ak.is_valid(result)
    assert result.to_list() == [[0, 0, 0, 0, 1, 0, 1], [1, 1, 1, 1, 0, 1, 0]]
    assert result.type == ak.types.ArrayType(
        ak.types.ListType(ak.types.NumpyType("int64")), 2
    )