File: test_1567_fix_longlong_in_Index.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 (39 lines) | stat: -rw-r--r-- 1,117 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
# 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_fix_longlong_type_passed_to_index_1530():
    a = np.asarray([0, 5, 10, 15, 20, 25], dtype=np.longlong)
    index = ak.index.Index64(a)
    content = ak.contents.NumpyArray(
        np.asarray(
            [101, 118, 116, 45, 48, 101, 118, 116, 45, 49, 101, 118], dtype=np.int64
        )
    )
    listoffsetarray = ak.contents.ListOffsetArray(index, content)

    assert ak.to_list(listoffsetarray) == [
        [101, 118, 116, 45, 48],
        [101, 118, 116, 45, 49],
        [101, 118],
        [],
        [],
    ]


def test_typetracer_view_method():
    a = np.asarray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=np.longlong)
    b = ak.contents.NumpyArray(a)
    c = np.array([7, 3, 3, 5], dtype=np.longlong)
    e = ak.index.Index(b.to_typetracer()[c].data)
    f = ak.index.Index(a)

    assert e.form == f.form
    assert ak.to_list(b[c]) == ak.to_list(a[c])
    assert b.to_typetracer()[c].form == b[c].form