12
12
[
13
13
pytest .param (bh .storage .AtomicInt64 (), "int" , id = "atomic_int" ),
14
14
pytest .param (bh .storage .Int64 (), "int" , id = "int" ),
15
- pytest .param (bh .storage .Unlimited (), "double" , id = "unlimited" ), # This always renders as double
15
+ pytest .param (
16
+ bh .storage .Unlimited (), "double" , id = "unlimited"
17
+ ), # This always renders as double
16
18
pytest .param (bh .storage .Double (), "double" , id = "double" ),
17
- ])
19
+ ],
20
+ )
18
21
def test_simple_to_dict (storage_type : bh .storage .Storage , expected_type : str ) -> None :
19
22
h = bh .Histogram (
20
23
bh .axis .Regular (10 , 0 , 1 ),
@@ -33,6 +36,7 @@ def test_simple_to_dict(storage_type: bh.storage.Storage, expected_type: str) ->
33
36
assert data ["storage" ]["type" ] == expected_type
34
37
assert data ["storage" ]["data" ] == pytest .approx (np .zeros (12 ))
35
38
39
+
36
40
def test_weighed_to_dict () -> None :
37
41
h = bh .Histogram (
38
42
bh .axis .Integer (3 , 15 ),
@@ -51,11 +55,12 @@ def test_weighed_to_dict() -> None:
51
55
assert data ["storage" ]["data" ]["values" ] == pytest .approx (np .zeros (14 ))
52
56
assert data ["storage" ]["data" ]["variances" ] == pytest .approx (np .zeros (14 ))
53
57
58
+
54
59
def test_mean_to_dict () -> None :
55
60
h = bh .Histogram (
56
61
bh .axis .StrCategory (["one" , "two" , "three" ]),
57
62
storage = bh .storage .Mean (),
58
- metadata = {"name" : "hi" },
63
+ metadata = {"name" : "hi" },
59
64
)
60
65
data = generic .to_dict (h )
61
66
@@ -68,6 +73,7 @@ def test_mean_to_dict() -> None:
68
73
assert data ["storage" ]["data" ]["values" ] == pytest .approx (np .zeros (4 ))
69
74
assert data ["storage" ]["data" ]["variances" ] == pytest .approx (np .zeros (4 ))
70
75
76
+
71
77
def test_weighted_mean_to_dict () -> None :
72
78
h = bh .Histogram (
73
79
bh .axis .IntCategory ([1 , 2 , 3 ]),
@@ -81,9 +87,15 @@ def test_weighted_mean_to_dict() -> None:
81
87
assert data ["axes" ][0 ]["categories" ] == pytest .approx ([1 , 2 , 3 ])
82
88
assert data ["axes" ][0 ]["flow" ]
83
89
assert data ["storage" ]["type" ] == "weighted_mean"
84
- assert data ["storage" ]["data" ]["sum_of_weights" ] == pytest .approx (np .array ([20 , 40 , 60 , 10 ]))
85
- assert data ["storage" ]["data" ]["sum_of_weights_squared" ] == pytest .approx (np .array ([200 , 800 , 1800 , 50 ]))
86
- assert data ["storage" ]["data" ]["values" ] == pytest .approx (np .array ([100 , 200 , 300 , 1 ]))
90
+ assert data ["storage" ]["data" ]["sum_of_weights" ] == pytest .approx (
91
+ np .array ([20 , 40 , 60 , 10 ])
92
+ )
93
+ assert data ["storage" ]["data" ]["sum_of_weights_squared" ] == pytest .approx (
94
+ np .array ([200 , 800 , 1800 , 50 ])
95
+ )
96
+ assert data ["storage" ]["data" ]["values" ] == pytest .approx (
97
+ np .array ([100 , 200 , 300 , 1 ])
98
+ )
87
99
assert data ["storage" ]["data" ]["variances" ] == pytest .approx (np .zeros (4 ))
88
100
89
101
@@ -94,7 +106,8 @@ def test_weighted_mean_to_dict() -> None:
94
106
pytest .param (bh .storage .Int64 (), id = "int" ),
95
107
pytest .param (bh .storage .Double (), id = "double" ),
96
108
pytest .param (bh .storage .Unlimited (), id = "unlimited" ),
97
- ])
109
+ ],
110
+ )
98
111
def test_round_trip_simple (storage_type : bh .storage .Storage ) -> None :
99
112
h = bh .Histogram (
100
113
bh .axis .Regular (10 , 0 , 10 ),
@@ -126,6 +139,7 @@ def test_round_trip_weighted() -> None:
126
139
assert pytest .approx (np .array (h .axes [0 ])) == np .array (h2 .axes [0 ])
127
140
assert np .asarray (h ) == pytest .approx (h2 )
128
141
142
+
129
143
def test_round_trip_mean () -> None :
130
144
h = bh .Histogram (
131
145
bh .axis .StrCategory (["1" , "2" , "3" ]),
@@ -139,6 +153,7 @@ def test_round_trip_mean() -> None:
139
153
assert pytest .approx (np .array (h .axes [0 ])) == np .array (h2 .axes [0 ])
140
154
assert np .asarray (h ) == pytest .approx (h2 )
141
155
156
+
142
157
def test_round_trip_weighted_mean () -> None :
143
158
h = bh .Histogram (
144
159
bh .axis .IntCategory ([1 , 2 , 3 ]),
@@ -150,4 +165,4 @@ def test_round_trip_weighted_mean() -> None:
150
165
h2 = generic .from_dict (data )
151
166
152
167
assert pytest .approx (np .array (h .axes [0 ])) == np .array (h2 .axes [0 ])
153
- assert np .asarray (h ) == pytest .approx (h2 )
168
+ assert np .asarray (h ) == pytest .approx (h2 )
0 commit comments