File: test_1960_awkward_from_rdataframe.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 (49 lines) | stat: -rw-r--r-- 1,163 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
# 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

import awkward as ak
import awkward._connect.cling
import awkward._lookup

ROOT = pytest.importorskip("ROOT")

ROOT.ROOT.EnableImplicitMT(1)

compiler = ROOT.gInterpreter.Declare


def test_unknown_column_type():
    example1 = ak.Array([1.1, 2.2, 3.3, 4.4, 5.5])
    data_frame = ak.to_rdataframe(
        {
            "one_float": example1,
        }
    )

    compiler(
        """
    struct TwoInts {
        int a, b;
    };

    template<typename T>
    ROOT::RDF::RNode MyTransformation_to_TwoInts(ROOT::RDF::RNode df) {
        auto myFunc = [](T x){ return TwoInts{(int)x, (int)2*x};};
        return df.Define("two_ints", myFunc, {"one_float"});
    }
    """
    )

    data_frame_transformed = ROOT.MyTransformation_to_TwoInts[
        data_frame.GetColumnType("one_float")
    ](ROOT.RDF.AsRNode(data_frame))

    with pytest.raises(TypeError, match=r"column's type"):
        ak.from_rdataframe(
            data_frame_transformed,
            columns=("two_ints",),
        )