File: test_1936_with_field_broadcasting.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 (28 lines) | stat: -rw-r--r-- 801 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
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import pytest

import awkward as ak


def test_scalar():
    array = ak.Array({"x": [1, 2, 3]})
    array["x"] = 4
    assert array.to_list() == [{"x": 4}, {"x": 4}, {"x": 4}]


def test_array():
    array = ak.Array({"x": [1, 2, 3]})
    array["x"] = [4]
    assert array.to_list() == [{"x": 4}, {"x": 4}, {"x": 4}]


def test_where_non_sequence():
    array = ak.Array({"x": [{"y": 1}, {"y": 2}, {"y": 3}]})
    result = ak.with_field(array, 4, ("x", "y"))
    assert result.to_list() == [{"x": {"y": 4}}, {"x": {"y": 4}}, {"x": {"y": 4}}]

    with pytest.raises(TypeError, match=r"New fields may only be assigned "):
        result = ak.with_field(array, 4, iter(("x", "y")))