@@ -684,16 +684,20 @@ def __getitem__(self, index): # noqa: C901
684684
685685 integrations = set ()
686686 slices = []
687+ pick_each = dict ()
687688
688689 # Compute needed slices and projections
689690 for i , ind in enumerate (indexes ):
690691 if hasattr (ind , "__index__" ):
691- ind = slice (ind .__index__ (), ind .__index__ () + 1 , sum )
692-
692+ pick_each [i ] = ind .__index__ () + ( # type: ignore
693+ 1 if self .axes [i ].traits .underflow else 0
694+ )
695+ continue
693696 elif not isinstance (ind , slice ):
694697 raise IndexError (
695698 "Must be a slice, an integer, or follow the locator protocol."
696699 )
700+
697701 # If the dictionary brackets are forgotten, it's easy to put a slice
698702 # into a slice - adding a nicer error message in that case
699703 if any (isinstance (v , slice ) for v in (ind .start , ind .stop , ind .step )):
@@ -732,16 +736,25 @@ def __getitem__(self, index): # noqa: C901
732736 logger .debug ("Reduce with %s" , slices )
733737 reduced = self ._hist .reduce (* slices )
734738
735- if not integrations :
736- return self ._new_hist (reduced )
737- else :
738- projections = [i for i in range (self .ndim ) if i not in integrations ]
739-
740- return (
741- self ._new_hist (reduced .project (* projections ))
742- if projections
743- else reduced .sum (flow = True )
739+ if pick_each :
740+ my_slice = tuple (
741+ pick_each .get (i , slice (None )) for i in range (reduced .rank ())
744742 )
743+ logger .debug ("Slices: %s" , my_slice )
744+ axes = [
745+ reduced .axis (i ) for i in range (reduced .rank ()) if i not in pick_each
746+ ]
747+ logger .debug ("Axes: %s" , axes )
748+ new_reduced = reduced .__class__ (axes )
749+ new_reduced .view (flow = True )[...] = reduced .view (flow = True )[my_slice ]
750+ reduced = new_reduced
751+ integrations = {i - sum (j <= i for j in pick_each ) for i in integrations }
752+
753+ if integrations :
754+ projections = [i for i in range (reduced .rank ()) if i not in integrations ]
755+ reduced = reduced .project (* projections )
756+
757+ return self ._new_hist (reduced ) if reduced .rank () > 0 else reduced .sum (flow = True )
745758
746759 def __setitem__ (self , index , value ):
747760 """
0 commit comments