File: test_0286_broadcast_single_value_with_field.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 (25 lines) | stat: -rw-r--r-- 775 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
# 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  # noqa: F401

import awkward as ak

to_list = ak.operations.to_list


def test_broadcast_single_bool():
    base = ak.Array([[{"x": 0.1, "y": 0.2, "z": 0.3}, {"x": 0.4, "y": 0.5, "z": 0.6}]])
    base_new1 = ak.operations.with_field(base, True, "always_true")
    assert to_list(base_new1.always_true) == [[True, True]]
    base_new2 = ak.operations.with_field(base_new1, base.x > 0.3, "sometimes_true")
    assert to_list(base_new2.always_true) == [[True, True]]
    assert ak.operations.fields(base_new2) == [
        "x",
        "y",
        "z",
        "always_true",
        "sometimes_true",
    ]