6565T = TypeVar ("T" )
6666
6767
68- def _fill_cast (value : T , * , inner : bool = False ) -> Union [T , np .ndarray , Tuple [T , ...]]:
68+ def _fill_cast (
69+ value : T , * , inner : bool = False
70+ ) -> Union [T , "np.typing.NDArray[Any]" , Tuple [T , ...]]:
6971 """
7072 Convert to NumPy arrays. Some buffer objects do not get converted by forcecast.
7173 If not called by itself (inner=False), then will work through one level of tuple/list.
@@ -297,13 +299,13 @@ def ndim(self) -> int:
297299
298300 def view (
299301 self , flow : bool = False
300- ) -> Union [np .ndarray , WeightedSumView , WeightedMeanView , MeanView ]:
302+ ) -> Union [" np.typing.NDArray[Any]" , WeightedSumView , WeightedMeanView , MeanView ]:
301303 """
302304 Return a view into the data, optionally with overflow turned on.
303305 """
304306 return _to_view (self ._hist .view (flow ))
305307
306- def __array__ (self ) -> np .ndarray :
308+ def __array__ (self ) -> " np.typing.NDArray[Any]" :
307309 return self .view (False )
308310
309311 def __eq__ (self , other : Any ) -> bool :
@@ -312,11 +314,15 @@ def __eq__(self, other: Any) -> bool:
312314 def __ne__ (self , other : Any ) -> bool :
313315 return (not hasattr (other , "_hist" )) or self ._hist != other ._hist
314316
315- def __add__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
317+ def __add__ (
318+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
319+ ) -> H :
316320 result = self .copy (deep = False )
317321 return result .__iadd__ (other )
318322
319- def __iadd__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
323+ def __iadd__ (
324+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
325+ ) -> H :
320326 if isinstance (other , (int , float )) and other == 0 :
321327 return self
322328 self ._compute_inplace_op ("__iadd__" , other )
@@ -326,36 +332,52 @@ def __iadd__(self: H, other: Union["Histogram", np.ndarray, float]) -> H:
326332
327333 return self
328334
329- def __radd__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
335+ def __radd__ (
336+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
337+ ) -> H :
330338 return self + other
331339
332340 # If these fail, the underlying object throws the correct error
333- def __mul__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
341+ def __mul__ (
342+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
343+ ) -> H :
334344 result = self .copy (deep = False )
335345 return result ._compute_inplace_op ("__imul__" , other )
336346
337- def __rmul__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
347+ def __rmul__ (
348+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
349+ ) -> H :
338350 return self * other
339351
340- def __truediv__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
352+ def __truediv__ (
353+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
354+ ) -> H :
341355 result = self .copy (deep = False )
342356 return result ._compute_inplace_op ("__itruediv__" , other )
343357
344- def __div__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
358+ def __div__ (
359+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
360+ ) -> H :
345361 result = self .copy (deep = False )
346362 return result ._compute_inplace_op ("__idiv__" , other )
347363
348- def __idiv__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
364+ def __idiv__ (
365+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
366+ ) -> H :
349367 return self ._compute_inplace_op ("__idiv__" , other )
350368
351- def __itruediv__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
369+ def __itruediv__ (
370+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
371+ ) -> H :
352372 return self ._compute_inplace_op ("__itruediv__" , other )
353373
354- def __imul__ (self : H , other : Union ["Histogram" , np .ndarray , float ]) -> H :
374+ def __imul__ (
375+ self : H , other : Union ["Histogram" , "np.typing.NDArray[Any]" , float ]
376+ ) -> H :
355377 return self ._compute_inplace_op ("__imul__" , other )
356378
357379 def _compute_inplace_op (
358- self : H , name : str , other : Union ["Histogram" , np .ndarray , float ]
380+ self : H , name : str , other : Union ["Histogram" , " np.typing.NDArray[Any]" , float ]
359381 ) -> H :
360382 # Also takes CppHistogram, but that confuses mypy because it's hard to pick out
361383 if isinstance (other , Histogram ):
@@ -442,26 +464,26 @@ def fill(
442464 }:
443465 raise RuntimeError ("Mean histograms do not support threaded filling" )
444466
445- data = [np .array_split (a , threads ) for a in args_ars ]
467+ data = [np .array_split (a , threads ) for a in args_ars ] # type: ignore
446468
447469 if weight is None or np .isscalar (weight ):
448470 assert threads is not None
449471 weights = [weight_ars ] * threads
450472 else :
451- weights = np .array_split (weight_ars , threads )
473+ weights = np .array_split (weight_ars , threads ) # type: ignore
452474
453475 if sample_ars is None or np .isscalar (sample_ars ):
454476 assert threads is not None
455477 samples = [sample_ars ] * threads
456478 else :
457- samples = np .array_split (sample_ars , threads )
479+ samples = np .array_split (sample_ars , threads ) # type: ignore
458480
459481 if self ._hist ._storage_type is _core .storage .atomic_int64 :
460482
461483 def fun (
462484 weight : Optional [ArrayLike ],
463485 sample : Optional [ArrayLike ],
464- * args : np .ndarray ,
486+ * args : " np.typing.NDArray[Any]" ,
465487 ) -> None :
466488 self ._hist .fill (* args , weight = weight , sample = sample )
467489
@@ -471,7 +493,7 @@ def fun(
471493 def fun (
472494 weight : Optional [ArrayLike ],
473495 sample : Optional [ArrayLike ],
474- * args : np .ndarray ,
496+ * args : " np.typing.NDArray[Any]" ,
475497 ) -> None :
476498 local_hist = self ._hist .__copy__ ()
477499 local_hist .reset ()
@@ -646,7 +668,10 @@ def _compute_commonindex(
646668
647669 def to_numpy (
648670 self , flow : bool = False , * , dd : bool = False , view : bool = False
649- ) -> Union [Tuple [np .ndarray , ...], Tuple [np .ndarray , Tuple [np .ndarray , ...]]]:
671+ ) -> Union [
672+ Tuple ["np.typing.NDArray[Any]" , ...],
673+ Tuple ["np.typing.NDArray[Any]" , Tuple ["np.typing.NDArray[Any]" , ...]],
674+ ]:
650675 """
651676 Convert to a NumPy style tuple of return arrays. Edges are converted to
652677 match NumPy standards, with upper edge inclusive, unlike
@@ -887,7 +912,7 @@ def __setitem__(
887912 if (
888913 value .ndim > 0
889914 and len (view .dtype ) > 0 # type: ignore
890- and len (value .dtype ) == 0 # type: ignore
915+ and len (value .dtype ) == 0
891916 and len (view .dtype ) == value .shape [- 1 ] # type: ignore
892917 ):
893918 value_shape = value .shape [:- 1 ]
@@ -984,7 +1009,7 @@ def kind(self) -> Kind:
9841009 else :
9851010 return Kind .COUNT
9861011
987- def values (self , flow : bool = False ) -> np .ndarray :
1012+ def values (self , flow : bool = False ) -> " np.typing.NDArray[Any]" :
9881013 """
9891014 Returns the accumulated values. The counts for simple histograms, the
9901015 sum of weights for weighted histograms, the mean for profiles, etc.
@@ -995,7 +1020,7 @@ def values(self, flow: bool = False) -> np.ndarray:
9951020 :param flow: Enable flow bins. Not part of PlottableHistogram, but
9961021 included for consistency with other methods and flexibility.
9971022
998- :return: np.ndarray [np.float64]
1023+ :return: " np.typing.NDArray[Any]" [np.float64]
9991024 """
10001025
10011026 view = self .view (flow )
@@ -1005,7 +1030,7 @@ def values(self, flow: bool = False) -> np.ndarray:
10051030 else :
10061031 return view .value # type: ignore
10071032
1008- def variances (self , flow : bool = False ) -> Optional [np .ndarray ]:
1033+ def variances (self , flow : bool = False ) -> Optional [" np.typing.NDArray[Any]" ]:
10091034 """
10101035 Returns the estimated variance of the accumulated values. The sum of squared
10111036 weights for weighted histograms, the variance of samples for profiles, etc.
@@ -1026,7 +1051,7 @@ def variances(self, flow: bool = False) -> Optional[np.ndarray]:
10261051 :param flow: Enable flow bins. Not part of PlottableHistogram, but
10271052 included for consistency with other methods and flexibility.
10281053
1029- :return: np.ndarray [np.float64]
1054+ :return: " np.typing.NDArray[Any]" [np.float64]
10301055 """
10311056
10321057 view = self .view (flow )
@@ -1053,7 +1078,7 @@ def variances(self, flow: bool = False) -> Optional[np.ndarray]:
10531078 else :
10541079 return view .variance # type: ignore
10551080
1056- def counts (self , flow : bool = False ) -> np .ndarray :
1081+ def counts (self , flow : bool = False ) -> " np.typing.NDArray[Any]" :
10571082 """
10581083 Returns the number of entries in each bin for an unweighted
10591084 histogram or profile and an effective number of entries (defined below)
@@ -1073,7 +1098,7 @@ def counts(self, flow: bool = False) -> np.ndarray:
10731098 The larger the spread in weights, the smaller it is, but it is always 0
10741099 if filled 0 times, and 1 if filled once, and more than 1 otherwise.
10751100
1076- :return: np.ndarray [np.float64]
1101+ :return: " np.typing.NDArray[Any]" [np.float64]
10771102 """
10781103
10791104 view = self .view (flow )
0 commit comments