File: test_2267_broadcast_fields.py

package info (click to toggle)
python-awkward 2.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 24,932 kB
  • sloc: python: 178,875; cpp: 33,828; sh: 432; makefile: 21; javascript: 8
file content (31 lines) | stat: -rw-r--r-- 941 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
# 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():
    a, b, c = ak.broadcast_fields(
        [{"x": 1, "c": 4}],
        [{"y": 2, "c": 5}],
        [{"z": 3, "c": 6}],
    )
    assert ak.almost_equal(a, [{"x": 1, "c": 4, "y": None, "z": None}])
    assert ak.almost_equal(b, [{"x": None, "c": 5, "y": 2, "z": None}])
    assert ak.almost_equal(c, [{"x": None, "c": 6, "y": None, "z": 3}])


def test_nested():
    a, b, c = ak.broadcast_fields(
        [{"x": 1, "z": {"a": 2, "b": 3}}],
        [{"y": 2}],
        [{"y": 3, "z": {"c": 9}}],
    )
    assert ak.almost_equal(a, [{"x": 1, "z": {"a": 2, "b": 3, "c": None}, "y": None}])
    assert ak.almost_equal(b, [{"x": None, "z": None, "y": 2}])
    assert ak.almost_equal(
        c, [{"x": None, "z": {"a": None, "b": None, "c": 9}, "y": 3}]
    )