@@ -221,6 +221,32 @@ def test_areas(self):
221221 assert_allclose (h .hist .areas (["var2" , "var3" ]), np .outer (w2 , w3 ))
222222 assert_allclose (h .hist .areas (), reduce (np .multiply , np .ix_ (w1 , w2 , w3 )))
223223
224+ def test_areas_flow (self ):
225+ ax1 = bh .axis .Regular (5 , 0 , 10 )
226+ ax2 = bh .axis .Regular (5 , 0 , 10 )
227+ h = get_hist (ax1 , ax2 , flow = True )
228+
229+ ref = np .asarray (
230+ [
231+ [1 , 1 , 1 , 1 , 1 , 1 , 1 ],
232+ [1 , 4 , 4 , 4 , 4 , 4 , 1 ],
233+ [1 , 4 , 4 , 4 , 4 , 4 , 1 ],
234+ [1 , 4 , 4 , 4 , 4 , 4 , 1 ],
235+ [1 , 4 , 4 , 4 , 4 , 4 , 1 ],
236+ [1 , 4 , 4 , 4 , 4 , 4 , 1 ],
237+ [1 , 1 , 1 , 1 , 1 , 1 , 1 ],
238+ ]
239+ )
240+
241+ assert_allclose (h .hist .areas (), ref )
242+
243+ def test_without_flow (self ):
244+ h = get_hist (bh .axis .Regular (5 , 0.0 , 1.0 ))
245+ assert_allclose (h .hist .bins (), [- np .inf , 0.0 , 0.2 , 0.4 , 0.6 , 0.8 , np .inf ])
246+ assert_allclose (h .hist .bins (flow = False ), [0.0 , 0.2 , 0.4 , 0.6 , 0.8 ])
247+ assert_allclose (h .hist .edges (flow = False ), [0.0 , 0.2 , 0.4 , 0.6 , 0.8 , 1.0 ])
248+ assert_allclose (h .hist .widths (flow = False ), [0.2 , 0.2 , 0.2 , 0.2 , 0.2 ])
249+
224250
225251class TestTransformBins :
226252 def test_apply (self ):
@@ -288,6 +314,23 @@ def test_normalization():
288314 assert_allclose (h , ref )
289315
290316
317+ def test_normalization_flow ():
318+ x = get_array ([50 ], name = "var1" )
319+ y = get_array ([50 ], name = "var2" )
320+ h = xh .histogramdd (x , y , bins = 10 , range = [(0 , 1 )] * 2 , flow = True )
321+ assert_allclose (
322+ h .hist .normalize ().hist .remove_flow (),
323+ h .hist .remove_flow ().hist .normalize (),
324+ )
325+
326+ # borders have not been modified
327+ norm = h .hist .normalize ()
328+ assert (norm .isel (var1_bins = 0 ) == h .isel (var1_bins = 0 )).all ()
329+ assert (norm .isel (var1_bins = - 1 ) == h .isel (var1_bins = - 1 )).all ()
330+ assert (norm .isel (var2_bins = 0 ) == h .isel (var2_bins = 0 )).all ()
331+ assert (norm .isel (var2_bins = - 1 ) == h .isel (var2_bins = - 1 )).all ()
332+
333+
291334class TestStatistics :
292335 ax = bh .axis .Regular (30 , 0.0 , 10.0 )
293336
0 commit comments