File: test_3051_to_cuda.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 (57 lines) | stat: -rw-r--r-- 1,656 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
from __future__ import annotations

import pytest

import awkward as ak

cudf = pytest.importorskip("cudf")
cupy = pytest.importorskip("cupy")


def test_jagged():
    arr = ak.Array([[[1, 2, 3], [], [3, 4]], []])
    out = ak.to_cudf(arr)
    assert isinstance(out, cudf.Series)
    assert out.to_arrow().tolist() == [[[1, 2, 3], [], [3, 4]], []]


def test_nested():
    arr = ak.Array(
        [{"a": 0, "b": 1.0, "c": {"d": 0}}, {"a": 1, "b": 0.0, "c": {"d": 1}}]
    )
    out = ak.to_cudf(arr)
    assert isinstance(out, cudf.Series)
    assert out.to_arrow().tolist() == [
        {"a": 0, "b": 1.0, "c": {"d": 0}},
        {"a": 1, "b": 0.0, "c": {"d": 1}},
    ]


def test_null():
    arr = ak.Array([12, None, 21, 12])
    # calls ByteMaskedArray._to_cudf not NumpyArray
    out = ak.to_cudf(arr)
    assert isinstance(out, cudf.Series)
    assert out.to_arrow().tolist() == [12, None, 21, 12]

    # True is valid, LSB order
    arr2 = ak.Array(arr.layout.to_BitMaskedArray(True, True))
    out = ak.to_cudf(arr2)
    assert isinstance(out, cudf.Series)
    assert out.to_arrow().tolist() == [12, None, 21, 12]

    # reversed LSB (should be rare, involves extra work!)
    arr3 = ak.Array(arr.layout.to_BitMaskedArray(True, False))
    out = ak.to_cudf(arr3)
    assert isinstance(out, cudf.Series)
    assert out.to_arrow().tolist() == [12, None, 21, 12]


def test_strings():
    arr = ak.Array(["hey", "hi", "hum"])
    out = ak.to_cudf(arr)
    assert out.to_arrow().tolist() == ["hey", "hi", "hum"]

    arr = ak.Array(["hey", "hi", None, "hum"])
    out = ak.to_cudf(arr)
    assert out.to_arrow().tolist() == ["hey", "hi", None, "hum"]