Skip to content

Commit 9ffc924

Browse files
TYP: remove some ignores - nansum, _get_counts_nanvar (#42400)
1 parent 00ceed4 commit 9ffc924

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

pandas/core/frame.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6162,9 +6162,9 @@ def f(vals) -> tuple[np.ndarray, int]:
61626162
return labels.astype("i8", copy=False), len(shape)
61636163

61646164
if subset is None:
6165-
# Incompatible types in assignment
6166-
# (expression has type "Index", variable has type "Sequence[Any]")
6167-
# (pending on https://github.com/pandas-dev/pandas/issues/28770)
6165+
# https://github.com/pandas-dev/pandas/issues/28770
6166+
# Incompatible types in assignment (expression has type "Index", variable
6167+
# has type "Sequence[Any]")
61686168
subset = self.columns # type: ignore[assignment]
61696169
elif (
61706170
not np.iterable(subset)
@@ -6242,6 +6242,7 @@ def sort_values( # type: ignore[override]
62426242
keys, orders=ascending, na_position=na_position, key=key
62436243
)
62446244
elif len(by):
6245+
# len(by) == 1
62456246

62466247
by = by[0]
62476248
k = self._get_label_or_level_values(by, axis=axis)

pandas/core/nanops.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,7 @@ def nansum(
581581
if is_float_dtype(dtype):
582582
dtype_sum = dtype
583583
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)
587585

588586
the_sum = values.sum(axis, dtype=dtype_sum)
589587
the_sum = _maybe_null_out(the_sum, axis, mask, values.shape, min_count=min_count)
@@ -787,7 +785,7 @@ def _get_counts_nanvar(
787785
axis: int | None,
788786
ddof: int,
789787
dtype: Dtype = float,
790-
) -> tuple[int | np.ndarray, int | np.ndarray]:
788+
) -> tuple[int | float | np.ndarray, int | float | np.ndarray]:
791789
"""
792790
Get the count of non-null values along an axis, accounting
793791
for degrees of freedom.
@@ -807,8 +805,8 @@ def _get_counts_nanvar(
807805
808806
Returns
809807
-------
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
812810
"""
813811
dtype = get_dtype(dtype)
814812
count = _get_counts(values_shape, mask, axis, dtype=dtype)
@@ -820,16 +818,13 @@ def _get_counts_nanvar(
820818
count = np.nan
821819
d = np.nan
822820
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
833828

834829

835830
@bottleneck_switch(ddof=1)

0 commit comments

Comments
 (0)