15
15
@pytest .mark .parametrize (
16
16
("storage_type" , "fill_args" , "fill_kwargs" ),
17
17
[
18
- pytest .param (bh .storage .Weight (), [0.3 , 0.3 , 0.4 , 1.2 ], {}, id = "weight" ),
18
+ pytest .param (bh .storage .Double (), [0.3 , 0.3 , 0.4 , 1.2 ], {}, id = "double" ),
19
+ pytest .param (bh .storage .Int64 (), [0.3 , 0.3 , 0.4 , 1.2 ], {}, id = "int64" ),
19
20
pytest .param (
20
- bh .storage .WeightedMean (),
21
- [0.3 , 0.3 , 0.4 , 1.2 , 1.6 ],
22
- {"sample" : [1 , 2 , 3 , 4 , 4 ], "weight" : [1 , 1 , 1 , 1 , 2 ]},
23
- id = "weighted_mean" ,
21
+ bh .storage .AtomicInt64 (), [0.3 , 0.3 , 0.4 , 1.2 ], {}, id = "atomicint"
24
22
),
23
+ pytest .param (bh .storage .Unlimited (), [0.3 , 0.3 , 0.4 , 1.2 ], {}, id = "unlimited" ),
24
+ pytest .param (bh .storage .Weight (), [0.3 , 0.3 , 0.4 , 1.2 ], {}, id = "weight" ),
25
25
pytest .param (
26
26
bh .storage .Mean (),
27
27
[0.3 , 0.3 , 0.4 , 1.2 , 1.6 ],
28
28
{"sample" : [1 , 2 , 3 , 4 , 4 ]},
29
29
id = "mean" ,
30
30
),
31
+ pytest .param (
32
+ bh .storage .WeightedMean (),
33
+ [0.3 , 0.3 , 0.4 , 1.2 , 1.6 ],
34
+ {"sample" : [1 , 2 , 3 , 4 , 4 ], "weight" : [1 , 1 , 1 , 1 , 2 ]},
35
+ id = "weighted_mean" ,
36
+ ),
31
37
],
32
38
)
33
39
def test_hdf5_storage (
@@ -51,7 +57,14 @@ def test_hdf5_storage(
51
57
52
58
# checking types of the reconstructed axes
53
59
assert type (actual_hist .axes [0 ]) is type (re_constructed_hist .axes [0 ])
54
- assert actual_hist .storage_type == re_constructed_hist .storage_type
60
+
61
+ if isinstance (storage_type , bh .storage .Unlimited ):
62
+ actual_hist_storage = bh .storage .Double ()
63
+ elif isinstance (storage_type , bh .storage .AtomicInt64 ):
64
+ actual_hist_storage = bh .storage .Int64 ()
65
+ else :
66
+ actual_hist_storage = storage_type
67
+ assert isinstance (actual_hist_storage , re_constructed_hist .storage_type )
55
68
56
69
# checking values of the essential inputs of the axes
57
70
assert actual_hist .axes [0 ].traits == re_constructed_hist .axes [0 ].traits
@@ -76,3 +89,43 @@ def test_hdf5_storage(
76
89
assert actual_hist .counts () == pytest .approx (
77
90
re_constructed_hist .counts (), abs = 1e-4 , rel = 1e-9
78
91
)
92
+
93
+
94
+ def test_hdf5_2d (tmp_path : Path ) -> None :
95
+ h = bh .Histogram (bh .axis .Integer (0 , 4 ), bh .axis .StrCategory (["a" , "b" , "c" ]))
96
+ h .fill ([0 , 1 , 1 , 1 ], ["a" , "b" , "b" , "c" ])
97
+
98
+ filepath = tmp_path / "hist.h5"
99
+ with h5py .File (filepath , "x" ) as f :
100
+ grp = f .create_group ("test_hist" )
101
+ s .write_hdf5_schema (grp , h )
102
+
103
+ with h5py .File (filepath ) as f :
104
+ re_constructed_hist = s .read_hdf5_schema (f ["test_hist" ])
105
+
106
+ actual_hist = h .copy ()
107
+
108
+ assert isinstance (re_constructed_hist .axes [0 ], bh .axis .Regular )
109
+ assert type (actual_hist .axes [1 ]) is type (re_constructed_hist .axes [1 ])
110
+
111
+ assert (
112
+ actual_hist .axes [0 ].traits .underflow
113
+ == re_constructed_hist .axes [0 ].traits .underflow
114
+ )
115
+ assert (
116
+ actual_hist .axes [0 ].traits .overflow
117
+ == re_constructed_hist .axes [0 ].traits .overflow
118
+ )
119
+ assert (
120
+ actual_hist .axes [0 ].traits .circular
121
+ == re_constructed_hist .axes [0 ].traits .circular
122
+ )
123
+ assert actual_hist .axes [1 ].traits == re_constructed_hist .axes [1 ].traits
124
+
125
+ assert np .asarray (actual_hist .axes [0 ].edges ) == pytest .approx (
126
+ np .asarray (re_constructed_hist .axes [0 ].edges )
127
+ )
128
+ assert list (actual_hist .axes [1 ]) == list (re_constructed_hist .axes [1 ])
129
+
130
+ assert h .values () == pytest .approx (re_constructed_hist .values ())
131
+ assert h .values (flow = True ) == pytest .approx (re_constructed_hist .values (flow = True ))
0 commit comments