Skip to content

Commit 6f21ec8

Browse files
authored
mypy fixups- something upgraded? (#41593)
1 parent a246270 commit 6f21ec8

File tree

9 files changed

+15
-58
lines changed

9 files changed

+15
-58
lines changed

pandas/core/arrays/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,7 @@ def size(self) -> int:
493493
"""
494494
The number of elements in the array.
495495
"""
496-
# error: Incompatible return value type (got "number", expected "int")
497-
return np.prod(self.shape) # type: ignore[return-value]
496+
return np.prod(self.shape)
498497

499498
@property
500499
def ndim(self) -> int:

pandas/core/arrays/sparse/accessor.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,8 @@ def density(self) -> float:
354354
"""
355355
Ratio of non-sparse points to total (dense) data points.
356356
"""
357-
# error: Incompatible return value type (got "number", expected "float")
358357
tmp = np.mean([column.array.density for _, column in self._parent.items()])
359-
return tmp # type: ignore[return-value]
358+
return tmp
360359

361360
@staticmethod
362361
def _prep_index(data, index, columns):

pandas/core/generic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ def size(self) -> int:
693693
>>> df.size
694694
4
695695
"""
696-
# error: Incompatible return value type (got "number", expected "int")
697-
return np.prod(self.shape) # type: ignore[return-value]
696+
return np.prod(self.shape)
698697

699698
@overload
700699
def set_axis(

pandas/core/nanops.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -588,17 +588,9 @@ def nansum(
588588
dtype_sum = np.float64 # type: ignore[assignment]
589589

590590
the_sum = values.sum(axis, dtype=dtype_sum)
591-
# error: Incompatible types in assignment (expression has type "float", variable has
592-
# type "Union[number, ndarray]")
593-
# error: Argument 1 to "_maybe_null_out" has incompatible type "Union[number,
594-
# ndarray]"; expected "ndarray"
595-
the_sum = _maybe_null_out( # type: ignore[assignment]
596-
the_sum, axis, mask, values.shape, min_count=min_count # type: ignore[arg-type]
597-
)
591+
the_sum = _maybe_null_out(the_sum, axis, mask, values.shape, min_count=min_count)
598592

599-
# error: Incompatible return value type (got "Union[number, ndarray]", expected
600-
# "float")
601-
return the_sum # type: ignore[return-value]
593+
return the_sum
602594

603595

604596
def _mask_datetimelike_result(
@@ -1343,12 +1335,10 @@ def nanprod(
13431335
values = values.copy()
13441336
values[mask] = 1
13451337
result = values.prod(axis)
1346-
# error: Argument 1 to "_maybe_null_out" has incompatible type "Union[number,
1347-
# ndarray]"; expected "ndarray"
13481338
# error: Incompatible return value type (got "Union[ndarray, float]", expected
13491339
# "float")
13501340
return _maybe_null_out( # type: ignore[return-value]
1351-
result, axis, mask, values.shape, min_count=min_count # type: ignore[arg-type]
1341+
result, axis, mask, values.shape, min_count=min_count
13521342
)
13531343

13541344

@@ -1424,13 +1414,7 @@ def _get_counts(
14241414
# expected "Union[int, float, ndarray]")
14251415
return dtype.type(count) # type: ignore[return-value]
14261416
try:
1427-
# error: Incompatible return value type (got "Union[ndarray, generic]", expected
1428-
# "Union[int, float, ndarray]")
1429-
# error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has incompatible type
1430-
# "Union[ExtensionDtype, dtype]"; expected "Union[dtype, None, type,
1431-
# _SupportsDtype, str, Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]],
1432-
# List[Any], _DtypeDict, Tuple[Any, Any]]"
1433-
return count.astype(dtype) # type: ignore[return-value,arg-type]
1417+
return count.astype(dtype)
14341418
except AttributeError:
14351419
# error: Argument "dtype" to "array" has incompatible type
14361420
# "Union[ExtensionDtype, dtype]"; expected "Union[dtype, None, type,

pandas/core/reshape/reshape.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ def _make_selectors(self):
176176
self.full_shape = ngroups, stride
177177

178178
selector = self.sorted_labels[-1] + stride * comp_index + self.lift
179-
# error: Argument 1 to "zeros" has incompatible type "number"; expected
180-
# "Union[int, Sequence[int]]"
181-
mask = np.zeros(np.prod(self.full_shape), dtype=bool) # type: ignore[arg-type]
179+
mask = np.zeros(np.prod(self.full_shape), dtype=bool)
182180
mask.put(selector, True)
183181

184182
if mask.sum() < len(self.index):

pandas/core/sorting.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -630,22 +630,15 @@ def get_group_index_sorter(
630630
np.ndarray[np.intp]
631631
"""
632632
if ngroups is None:
633-
# error: Incompatible types in assignment (expression has type "number[Any]",
634-
# variable has type "Optional[int]")
635-
ngroups = 1 + group_index.max() # type: ignore[assignment]
633+
ngroups = 1 + group_index.max()
636634
count = len(group_index)
637635
alpha = 0.0 # taking complexities literally; there may be
638636
beta = 1.0 # some room for fine-tuning these parameters
639-
# error: Unsupported operand types for * ("float" and "None")
640-
do_groupsort = count > 0 and (
641-
(alpha + beta * ngroups) < (count * np.log(count)) # type: ignore[operator]
642-
)
637+
do_groupsort = count > 0 and ((alpha + beta * ngroups) < (count * np.log(count)))
643638
if do_groupsort:
644-
# Argument 2 to "groupsort_indexer" has incompatible type
645-
# "Optional[int]"; expected "int"
646639
sorter, _ = algos.groupsort_indexer(
647640
ensure_platform_int(group_index),
648-
ngroups, # type: ignore[arg-type]
641+
ngroups,
649642
)
650643
# sorter _should_ already be intp, but mypy is not yet able to verify
651644
else:

pandas/io/formats/format.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -1664,19 +1664,9 @@ def format_percentiles(
16641664
).astype(int)
16651665
prec = max(1, prec)
16661666
out = np.empty_like(percentiles, dtype=object)
1667-
# error: No overload variant of "__getitem__" of "list" matches argument type
1668-
# "Union[bool_, ndarray]"
1669-
out[int_idx] = (
1670-
percentiles[int_idx].astype(int).astype(str) # type: ignore[call-overload]
1671-
)
1667+
out[int_idx] = percentiles[int_idx].astype(int).astype(str)
16721668

1673-
# error: Item "float" of "Union[Any, float, str]" has no attribute "round"
1674-
# error: Item "str" of "Union[Any, float, str]" has no attribute "round"
1675-
# error: Invalid index type "Union[bool_, Any]" for "Union[ndarray, List[Union[int,
1676-
# float]], List[float], List[Union[str, float]]]"; expected type "int"
1677-
out[~int_idx] = (
1678-
percentiles[~int_idx].round(prec).astype(str) # type: ignore[union-attr,index]
1679-
)
1669+
out[~int_idx] = percentiles[~int_idx].round(prec).astype(str)
16801670
return [i + "%" for i in out]
16811671

16821672

pandas/io/parsers/base_parser.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,7 @@ def _infer_types(self, values, na_values, try_num_bool=True):
684684
# error: Argument 2 to "isin" has incompatible type "List[Any]"; expected
685685
# "Union[Union[ExtensionArray, ndarray], Index, Series]"
686686
mask = algorithms.isin(values, list(na_values)) # type: ignore[arg-type]
687-
# error: Incompatible types in assignment (expression has type
688-
# "number[Any]", variable has type "int")
689-
na_count = mask.sum() # type: ignore[assignment]
687+
na_count = mask.sum()
690688
if na_count > 0:
691689
if is_integer_dtype(values):
692690
values = values.astype(np.float64)

pandas/io/pytables.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -3378,10 +3378,7 @@ def validate_multiindex(
33783378
@property
33793379
def nrows_expected(self) -> int:
33803380
""" based on our axes, compute the expected nrows """
3381-
# error: Incompatible return value type (got "number", expected "int")
3382-
return np.prod( # type: ignore[return-value]
3383-
[i.cvalues.shape[0] for i in self.index_axes]
3384-
)
3381+
return np.prod([i.cvalues.shape[0] for i in self.index_axes])
33853382

33863383
@property
33873384
def is_exists(self) -> bool:

0 commit comments

Comments
 (0)