57
57
CppAxis = NewType ("CppAxis" , object )
58
58
59
59
SimpleIndexing = Union [SupportsIndex , slice ]
60
- InnerIndexing = Union [SimpleIndexing , Callable [[Axis ], int ], "ellipsis" ]
60
+ InnerIndexing = Union [SimpleIndexing , Callable [[Axis ], int ]]
61
61
FullInnerIndexing = Union [InnerIndexing , List [InnerIndexing ]]
62
62
IndexingWithMapping = Union [FullInnerIndexing , Mapping [int , FullInnerIndexing ]]
63
- IndexingExpr = Union [IndexingWithMapping , Tuple [IndexingWithMapping , ...]]
63
+ IndexingExpr = Union [IndexingWithMapping , Tuple [IndexingWithMapping , ...], "ellipsis" ]
64
64
65
65
T = TypeVar ("T" )
66
66
@@ -621,19 +621,23 @@ def _compute_uhi_index(self, index: InnerIndexing, axis: int) -> SimpleIndexing:
621
621
"""
622
622
# Support sum and rebin directly
623
623
if index is sum or hasattr (index , "factor" ): # type: ignore[comparison-overlap]
624
- index = slice (None , None , index )
624
+ return slice (None , None , index )
625
625
626
626
# General locators
627
627
# Note that MyPy doesn't like these very much - the fix
628
628
# will be to properly set input types
629
- elif callable (index ):
630
- index = index (self .axes [axis ])
631
- elif isinstance (index , SupportsIndex ):
629
+ if callable (index ):
630
+ return index (self .axes [axis ])
631
+
632
+ if isinstance (index , float ):
633
+ raise TypeError (f"Index { index } must be an integer, not float" )
634
+
635
+ if isinstance (index , SupportsIndex ):
632
636
if abs (int (index )) >= self ._hist .axis (axis ).size :
633
637
raise IndexError ("histogram index is out of range" )
634
- index %= self ._hist .axis (axis ).size
638
+ return index % self ._hist .axis (axis ).size # type: ignore[no-any-return]
635
639
636
- return index # type: ignore[return-value]
640
+ return index
637
641
638
642
def _compute_commonindex (
639
643
self , index : IndexingExpr
@@ -656,10 +660,10 @@ def _compute_commonindex(
656
660
657
661
# Normalize -> h[i] == h[i,]
658
662
else :
659
- if not isinstance (index , tuple ):
660
- index = ( index ,)
663
+ tuple_index = ( index ,) if not isinstance (index , tuple ) else index
664
+
661
665
# Now a list
662
- indexes = _expand_ellipsis (index , hist .rank ())
666
+ indexes = _expand_ellipsis (tuple_index , hist .rank ())
663
667
664
668
if len (indexes ) != hist .rank ():
665
669
raise IndexError ("Wrong number of indices for histogram" )
@@ -669,7 +673,7 @@ def _compute_commonindex(
669
673
for i in range (len (indexes )): # pylint: disable=consider-using-enumerate
670
674
# Support list of UHI indexers
671
675
if isinstance (indexes [i ], list ):
672
- indexes [i ] = [self ._compute_uhi_index (index , i ) for index in indexes [i ]]
676
+ indexes [i ] = [self ._compute_uhi_index (ind , i ) for ind in indexes [i ]]
673
677
else :
674
678
indexes [i ] = self ._compute_uhi_index (indexes [i ], i )
675
679
0 commit comments