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

from __future__ import annotations

import pathlib
import pickle

import numpy as np

SAMPLES_DIR = pathlib.Path(__file__).parent / "samples"


def test_numpyarray():
    with open(SAMPLES_DIR / "awkward1-numpyarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [1, 2, 3]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_partitioned_numpyarray():
    with open(SAMPLES_DIR / "awkward1-partitioned-numpyarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [1, 2, 3, 4, 5, 6]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_listoffsetarray():
    with open(SAMPLES_DIR / "awkward1-listoffsetarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [[1.1, 2.2, 3.3], [], [4.4, 5.5]]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_regulararray():
    with open(SAMPLES_DIR / "awkward1-regulararray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == np.arange(2 * 3 * 5).reshape(2, 3, 5).tolist()
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_strings():
    with open(SAMPLES_DIR / "awkward1-strings.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == ["one", "two", "three"]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_emptyarray():
    with open(SAMPLES_DIR / "awkward1-emptyarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == []
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_indexedoptionarray():
    with open(SAMPLES_DIR / "awkward1-indexedoptionarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [1, 2, None, None, 3]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_bytemaskedarray():
    with open(SAMPLES_DIR / "awkward1-bytemaskedarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [1, 2, None, None, 5]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_unmaskedarray():
    with open(SAMPLES_DIR / "awkward1-unmaskedarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [1, 2, 3]
        assert str(array.type) == "3 * ?int64"
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_recordarray():
    with open(SAMPLES_DIR / "awkward1-recordarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [{"x": 1, "y": 1.1}, {"x": 2, "y": 2.2}]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_recordarray_tuple():
    with open(SAMPLES_DIR / "awkward1-recordarray-tuple.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [(1, 1.1), (2, 2.2)]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form


def test_unionarray():
    with open(SAMPLES_DIR / "awkward1-unionarray.pkl", "rb") as file:
        array = pickle.load(file)
        assert array.to_list() == [1, 2, [3, 4, 5]]
        assert pickle.loads(pickle.dumps(array)).layout.form == array.layout.form