Skip to content

TYP: remove some ignores - nansum, _get_counts_nanvar #42400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6162,9 +6162,9 @@ def f(vals) -> tuple[np.ndarray, int]:
return labels.astype("i8", copy=False), len(shape)

if subset is None:
# Incompatible types in assignment
# (expression has type "Index", variable has type "Sequence[Any]")
# (pending on https://github.com/pandas-dev/pandas/issues/28770)
# https://github.com/pandas-dev/pandas/issues/28770
# Incompatible types in assignment (expression has type "Index", variable
# has type "Sequence[Any]")
subset = self.columns # type: ignore[assignment]
elif (
not np.iterable(subset)
Expand Down Expand Up @@ -6242,6 +6242,7 @@ def sort_values( # type: ignore[override]
keys, orders=ascending, na_position=na_position, key=key
)
elif len(by):
# len(by) == 1

by = by[0]
k = self._get_label_or_level_values(by, axis=axis)
Expand Down
27 changes: 11 additions & 16 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,7 @@ def nansum(
if is_float_dtype(dtype):
dtype_sum = dtype
elif is_timedelta64_dtype(dtype):
# error: Incompatible types in assignment (expression has type
# "Type[float64]", variable has type "dtype")
dtype_sum = np.float64 # type: ignore[assignment]
dtype_sum = np.dtype(np.float64)

the_sum = values.sum(axis, dtype=dtype_sum)
the_sum = _maybe_null_out(the_sum, axis, mask, values.shape, min_count=min_count)
Expand Down Expand Up @@ -787,7 +785,7 @@ def _get_counts_nanvar(
axis: int | None,
ddof: int,
dtype: Dtype = float,
) -> tuple[int | np.ndarray, int | np.ndarray]:
) -> tuple[int | float | np.ndarray, int | float | np.ndarray]:
"""
Get the count of non-null values along an axis, accounting
for degrees of freedom.
Expand All @@ -807,8 +805,8 @@ def _get_counts_nanvar(

Returns
-------
count : scalar or array
d : scalar or array
count : int, np.nan or np.ndarray
d : int, np.nan or np.ndarray
"""
dtype = get_dtype(dtype)
count = _get_counts(values_shape, mask, axis, dtype=dtype)
Expand All @@ -820,16 +818,13 @@ def _get_counts_nanvar(
count = np.nan
d = np.nan
else:
# error: Incompatible types in assignment (expression has type
# "Union[bool, Any]", variable has type "ndarray")
mask2: np.ndarray = count <= ddof # type: ignore[assignment]
if mask2.any():
np.putmask(d, mask2, np.nan)
np.putmask(count, mask2, np.nan)
# error: Incompatible return value type (got "Tuple[Union[int, float,
# ndarray], Any]", expected "Tuple[Union[int, ndarray], Union[int,
# ndarray]]")
return count, d # type: ignore[return-value]
# count is not narrowed by is_scalar check
count = cast(np.ndarray, count)
mask = count <= ddof
if mask.any():
np.putmask(d, mask, np.nan)
np.putmask(count, mask, np.nan)
return count, d


@bottleneck_switch(ddof=1)
Expand Down