@@ -581,9 +581,7 @@ def nansum(
581
581
if is_float_dtype (dtype ):
582
582
dtype_sum = dtype
583
583
elif is_timedelta64_dtype (dtype ):
584
- # error: Incompatible types in assignment (expression has type
585
- # "Type[float64]", variable has type "dtype")
586
- dtype_sum = np .float64 # type: ignore[assignment]
584
+ dtype_sum = np .dtype (np .float64 )
587
585
588
586
the_sum = values .sum (axis , dtype = dtype_sum )
589
587
the_sum = _maybe_null_out (the_sum , axis , mask , values .shape , min_count = min_count )
@@ -787,7 +785,7 @@ def _get_counts_nanvar(
787
785
axis : int | None ,
788
786
ddof : int ,
789
787
dtype : Dtype = float ,
790
- ) -> tuple [int | np .ndarray , int | np .ndarray ]:
788
+ ) -> tuple [int | float | np .ndarray , int | float | np .ndarray ]:
791
789
"""
792
790
Get the count of non-null values along an axis, accounting
793
791
for degrees of freedom.
@@ -807,8 +805,8 @@ def _get_counts_nanvar(
807
805
808
806
Returns
809
807
-------
810
- count : scalar or array
811
- d : scalar or array
808
+ count : int, np.nan or np.ndarray
809
+ d : int, np.nan or np.ndarray
812
810
"""
813
811
dtype = get_dtype (dtype )
814
812
count = _get_counts (values_shape , mask , axis , dtype = dtype )
@@ -820,16 +818,13 @@ def _get_counts_nanvar(
820
818
count = np .nan
821
819
d = np .nan
822
820
else :
823
- # error: Incompatible types in assignment (expression has type
824
- # "Union[bool, Any]", variable has type "ndarray")
825
- mask2 : np .ndarray = count <= ddof # type: ignore[assignment]
826
- if mask2 .any ():
827
- np .putmask (d , mask2 , np .nan )
828
- np .putmask (count , mask2 , np .nan )
829
- # error: Incompatible return value type (got "Tuple[Union[int, float,
830
- # ndarray], Any]", expected "Tuple[Union[int, ndarray], Union[int,
831
- # ndarray]]")
832
- return count , d # type: ignore[return-value]
821
+ # count is not narrowed by is_scalar check
822
+ count = cast (np .ndarray , count )
823
+ mask = count <= ddof
824
+ if mask .any ():
825
+ np .putmask (d , mask , np .nan )
826
+ np .putmask (count , mask , np .nan )
827
+ return count , d
833
828
834
829
835
830
@bottleneck_switch (ddof = 1 )
0 commit comments