Skip to content

Commit 2cbeea7

Browse files
committed
Fix more typing
1 parent 149236a commit 2cbeea7

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

pandas/core/indexes/multi.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ def _verify_integrity(
462462
result_codes = []
463463
for i in range(len(levels)):
464464
if i in levels_to_verify:
465-
result_codes.append(self._validate_codes(levels[i], codes[i]))
465+
# error: Argument 1 to "_validate_codes" of "MultiIndex"
466+
# has incompatible type "Union[Any, Index]"; expected "List[Any]"
467+
result_codes.append(self._validate_codes(levels[i], codes[i])) # type: ignore[arg-type] # noqa: E501
466468
else:
467469
result_codes.append(codes[i])
468470

@@ -772,9 +774,9 @@ def _values(self) -> np.ndarray:
772774
):
773775
vals = vals.astype(object)
774776

775-
vals = np.array(vals, copy=False)
776-
vals = algos.take_nd(vals, codes, fill_value=index._na_value)
777-
values.append(vals)
777+
array_vals = np.array(vals, copy=False)
778+
array_vals = algos.take_nd(array_vals, codes, fill_value=index._na_value)
779+
values.append(array_vals)
778780

779781
arr = lib.fast_zip(values)
780782
return arr
@@ -840,7 +842,7 @@ def size(self) -> int:
840842
# Levels Methods
841843

842844
@cache_readonly
843-
def levels(self) -> tuple:
845+
def levels(self) -> tuple[Index, ...]:
844846
# Use cache_readonly to ensure that self.get_locs doesn't repeatedly
845847
# create new IndexEngine
846848
# https://github.com/pandas-dev/pandas/issues/31648

pandas/core/reshape/merge.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,11 @@ def _convert_to_multiindex(index: Index) -> MultiIndex:
17961796
join_codes = join_codes + [restore_codes]
17971797
join_names = join_names + [dropped_level_name]
17981798

1799-
return join_levels, join_codes, join_names
1799+
# error: Incompatible return value type
1800+
# (got "Tuple[List[Index], List[Any], List[Any]]",
1801+
# expected "Tuple[List[Index], ndarray[Any, dtype[signedinteger[Any]]],
1802+
# List[Hashable]]")
1803+
return join_levels, join_codes, join_names # type: ignore[return-value]
18001804

18011805

18021806
class _OrderedMerge(_MergeOperation):
@@ -2222,8 +2226,10 @@ def _get_multiindex_indexer(
22222226
join_keys: list[ArrayLike], index: MultiIndex, sort: bool
22232227
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]:
22242228
# left & right join labels and num. of levels at each location
2229+
# error: Argument 1 to "_factorize_keys" has incompatible type "Index";
2230+
# expected "Union[ExtensionArray, ndarray[Any, Any]]"
22252231
mapped = (
2226-
_factorize_keys(index.levels[n]._values, join_keys[n], sort=sort)
2232+
_factorize_keys(index.levels[n]._values, join_keys[n], sort=sort) # type: ignore[arg-type] # noqa: E501
22272233
for n in range(index.nlevels)
22282234
)
22292235
zipped = zip(*mapped)

pandas/core/window/rolling.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -837,13 +837,17 @@ def _apply_pairwise(
837837
result_names = list(result.index.names)
838838
else:
839839
idx_codes, idx_levels = factorize(result.index)
840+
idx_levels = cast(Index, idx_levels)
840841
result_codes = [idx_codes]
841842
result_levels = [idx_levels]
842843
result_names = [result.index.name]
843844

844845
# 3) Create the resulting index by combining 1) + 2)
845846
result_codes = groupby_codes + result_codes
846-
result_levels = groupby_levels + result_levels
847+
# error: Incompatible types in assignment
848+
# (expression has type "List[Union[Index, ndarray[Any, Any]]]",
849+
# variable has type "List[Index]")
850+
result_levels = groupby_levels + result_levels # type: ignore[assignment]
847851
result_names = self._grouper.names + result_names
848852

849853
result_index = MultiIndex(

0 commit comments

Comments
 (0)