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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE
from __future__ import annotations
import datetime
import numpy as np
import pytest # noqa: F401
import awkward as ak
def test():
array = ak.Array(
[
[{"x": 0.0, "y": []}, {"x": 1.1, "y": [1]}, {"x": 2.2, "y": [1, 2]}],
[],
[
{"x": 3.3, "y": [1, 2, None, 3]},
False,
False,
True,
{"x": 4.4, "y": [1, 2, None, 3, 4]},
],
]
)
assert ak.operations.full_like(array, 12.3).to_list() == [
[{"x": 12.3, "y": []}, {"x": 12.3, "y": [12]}, {"x": 12.3, "y": [12, 12]}],
[],
[
{"x": 12.3, "y": [12, 12, None, 12]},
True,
True,
True,
{"x": 12.3, "y": [12, 12, None, 12, 12]},
],
]
assert ak.operations.zeros_like(array).to_list() == [
[{"x": 0.0, "y": []}, {"x": 0.0, "y": [0]}, {"x": 0.0, "y": [0, 0]}],
[],
[
{"x": 0.0, "y": [0, 0, None, 0]},
False,
False,
False,
{"x": 0.0, "y": [0, 0, None, 0, 0]},
],
]
assert ak.operations.ones_like(array).to_list() == [
[{"x": 1.0, "y": []}, {"x": 1.0, "y": [1]}, {"x": 1.0, "y": [1, 1]}],
[],
[
{"x": 1.0, "y": [1, 1, None, 1]},
True,
True,
True,
{"x": 1.0, "y": [1, 1, None, 1, 1]},
],
]
array = ak.Array([["one", "two", "three"], [], ["four", "five"]])
assert ak.operations.full_like(array, "hello").to_list() == [
["hello", "hello", "hello"],
[],
["hello", "hello"],
]
assert ak.operations.full_like(array, 1).to_list() == [
["1", "1", "1"],
[],
["1", "1"],
]
assert ak.operations.full_like(array, 0).to_list() == [
["0", "0", "0"],
[],
["0", "0"],
]
assert ak.operations.ones_like(array).to_list() == [
["1", "1", "1"],
[],
["1", "1"],
]
assert ak.operations.zeros_like(array).to_list() == [
["", "", ""],
[],
["", ""],
]
array = ak.Array([[b"one", b"two", b"three"], [], [b"four", b"five"]])
assert ak.operations.full_like(array, b"hello").to_list() == [
[b"hello", b"hello", b"hello"],
[],
[b"hello", b"hello"],
]
assert ak.operations.full_like(array, 1).to_list() == [
[b"1", b"1", b"1"],
[],
[b"1", b"1"],
]
assert ak.operations.full_like(array, 0).to_list() == [
[b"0", b"0", b"0"],
[],
[b"0", b"0"],
]
assert ak.operations.ones_like(array).to_list() == [
[b"1", b"1", b"1"],
[],
[b"1", b"1"],
]
assert ak.operations.zeros_like(array).to_list() == [
[b"", b"", b""],
[],
[b"", b""],
]
def test_full_like_types():
array = ak.highlevel.Array(
np.array(["2020-07-27T10:41:11", "2019-01-01", "2020-01-01"], "datetime64[s]")
)
assert ak.operations.full_like(array, "2020-07-27T10:41:11").to_list() == [
datetime.datetime(2020, 7, 27, 10, 41, 11),
datetime.datetime(2020, 7, 27, 10, 41, 11),
datetime.datetime(2020, 7, 27, 10, 41, 11),
]
array = np.array(
["2020-07-27T10:41:11", "2019-01-01", "2020-01-01"], "datetime64[25s]"
)
assert ak.operations.full_like(array, "2021-06-03T10:00").to_list() == [
datetime.datetime(2021, 6, 3, 10, 0),
datetime.datetime(2021, 6, 3, 10, 0),
datetime.datetime(2021, 6, 3, 10, 0),
]
array = ak.contents.NumpyArray(np.array([0, 2, 2, 3], dtype="i4"))
assert str(ak.operations.full_like(array, 11, dtype="i8").type) == "4 * int64"
assert (
str(ak.operations.full_like(array, 11, dtype=np.dtype(np.int64)).type)
== "4 * int64"
)
assert str(ak.operations.full_like(array, 11, dtype=np.int64).type) == "4 * int64"
|