File tree 2 files changed +19
-0
lines changed
src/boost_histogram/_internal
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ def __str__(self):
37
37
)
38
38
39
39
def __setitem__ (self , ind , value ):
40
+ # `.value` really is ["value"] for an record array
41
+ if isinstance (ind , str ):
42
+ super (View , self ).__setitem__ (ind , value )
43
+ return
44
+
40
45
array = np .asarray (value )
41
46
if (
42
47
array .ndim == super (View , self ).__getitem__ (ind ).ndim + 1
Original file line number Diff line number Diff line change @@ -201,3 +201,17 @@ def test_setting_weighted_profile():
201
201
a .view ()._sum_of_weighted_deltas_squared ,
202
202
b .view ()["_sum_of_weighted_deltas_squared" ],
203
203
)
204
+
205
+
206
+ # Issue #486
207
+ def test_modify_weights_by_view ():
208
+ bins = [0 , 1 , 2 ]
209
+ hist = bh .Histogram (bh .axis .Variable (bins ), storage = bh .storage .Weight ())
210
+ yields = [3 , 4 ]
211
+ var = [0.1 , 0.2 ]
212
+ hist [...] = np .stack ([yields , var ], axis = - 1 )
213
+
214
+ hist .view ().value /= 2
215
+
216
+ assert hist .view ().value [0 ] == pytest .approx (1.5 )
217
+ assert hist .view ().value [1 ] == pytest .approx (2 )
You can’t perform that action at this time.
0 commit comments