Skip to content

Commit 64e398e

Browse files
committed
fixes to typing
1 parent e683d19 commit 64e398e

File tree

9 files changed

+16
-27
lines changed

9 files changed

+16
-27
lines changed

pandas/compat/numpy/function.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name) -> bool:
226226
skipna = True
227227

228228
validate_cum_func(args, kwargs, fname=name)
229-
return skipna # pyright: ignore[reportGeneralTypeIssues]
229+
return skipna
230230

231231

232232
ALLANY_DEFAULTS: dict[str, bool | None] = {}

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4089,8 +4089,8 @@ class animal locomotion
40894089
loc, new_index = index._get_loc_level(key, level=0)
40904090
if not drop_level:
40914091
if lib.is_integer(loc):
4092-
# error: Slice index must be an integer or None
4093-
new_index = index[loc : loc + 1] # type: ignore[misc]
4092+
loc = cast(int, loc)
4093+
new_index = index[loc : loc + 1]
40944094
else:
40954095
new_index = index[loc]
40964096
else:

pandas/core/indexes/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_objs_combined_axis(
7373
objs,
7474
intersect: bool = False,
7575
axis: Axis = 0,
76-
sort: bool | np.bool_ = True,
76+
sort: bool = True,
7777
copy: bool = False,
7878
) -> Index:
7979
"""
@@ -120,7 +120,7 @@ def _get_distinct_objs(objs: list[Index]) -> list[Index]:
120120
def _get_combined_index(
121121
indexes: list[Index],
122122
intersect: bool = False,
123-
sort: bool | np.bool_ = False,
123+
sort: bool = False,
124124
copy: bool = False,
125125
) -> Index:
126126
"""

pandas/core/indexes/multi.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,7 @@ def _partial_tup_index(self, tup: tuple, side: Literal["left", "right"] = "left"
26992699
for k, (lab, lev, level_codes) in enumerate(zipped):
27002700
section = level_codes[start:end]
27012701

2702+
loc: npt.NDArray[np.intp] | np.intp | int
27022703
if lab not in lev and not isna(lab):
27032704
# short circuit
27042705
try:
@@ -2710,10 +2711,7 @@ def _partial_tup_index(self, tup: tuple, side: Literal["left", "right"] = "left"
27102711
# non-comparable level, e.g. test_groupby_example
27112712
raise TypeError(f"Level type mismatch: {lab}")
27122713
if side == "right" and loc >= 0:
2713-
# error: Incompatible types in assignment (expression has type
2714-
# "Union[int, Any]", variable has type "Union[ndarray[Any,
2715-
# dtype[signedinteger[Any]]], signedinteger[Any]]")
2716-
loc -= 1 # type: ignore[assignment]
2714+
loc -= 1
27172715
return start + algos.searchsorted(section, loc, side=side)
27182716

27192717
idx = self._get_loc_single_level_index(lev, lab)
@@ -2933,8 +2931,8 @@ def get_loc_level(self, key, level: IndexLabel = 0, drop_level: bool = True):
29332931
loc, mi = self._get_loc_level(key, level=level)
29342932
if not drop_level:
29352933
if lib.is_integer(loc):
2936-
# error: Slice index must be an integer or None
2937-
mi = self[loc : loc + 1] # type: ignore[misc]
2934+
loc = cast(int, loc)
2935+
mi = self[loc : loc + 1]
29382936
else:
29392937
mi = self[loc]
29402938
return loc, mi

pandas/core/indexes/period.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,8 @@ def _maybe_convert_timedelta(self, other) -> int | npt.NDArray[np.int64]:
298298

299299
raise raise_on_incompatible(self, other)
300300
elif is_integer(other):
301-
# integer is passed to .shift via
302-
# _add_datetimelike_methods basically
303-
# but ufunc may pass integer to _add_delta
304-
# error: Incompatible return value type (got "Union[int, integer[Any]]",
305-
# expected "Union[int, ndarray[Any, dtype[signedinteger[_64Bit]]]]")
306-
return other # type: ignore[return-value]
301+
assert isinstance(other, int)
302+
return other
307303

308304
# raise when input doesn't have freq
309305
raise raise_on_incompatible(self, None)

pandas/core/reshape/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def __init__(
555555
raise ValueError(
556556
f"The 'sort' keyword only accepts boolean values; {sort} was passed."
557557
)
558-
self.sort = sort
558+
self.sort = cast(bool, sort)
559559

560560
self.ignore_index = ignore_index
561561
self.verify_integrity = verify_integrity

pandas/io/parsers/python_parser.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
ParserError,
3030
)
3131

32-
from pandas.core.dtypes.common import is_integer
3332
from pandas.core.dtypes.inference import is_dict_like
3433

3534
from pandas.io.common import (
@@ -1342,12 +1341,10 @@ def _validate_skipfooter_arg(skipfooter: int) -> int:
13421341
------
13431342
ValueError : 'skipfooter' was not a non-negative integer.
13441343
"""
1345-
if not is_integer(skipfooter):
1344+
if not isinstance(skipfooter, int):
13461345
raise ValueError("skipfooter must be an integer")
13471346

13481347
if skipfooter < 0:
13491348
raise ValueError("skipfooter cannot be negative")
13501349

1351-
# error: Incompatible return value type (got "Union[int, integer[Any]]",
1352-
# expected "int")
1353-
return skipfooter # type: ignore[return-value]
1350+
return skipfooter

pandas/io/sql.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from pandas.core.dtypes.common import (
4545
is_datetime64tz_dtype,
4646
is_dict_like,
47-
is_integer,
4847
is_list_like,
4948
)
5049
from pandas.core.dtypes.dtypes import DatetimeTZDtype
@@ -1022,8 +1021,7 @@ def insert(
10221021
chunk_iter = zip(*(arr[start_i:end_i] for arr in data_list))
10231022
num_inserted = exec_insert(conn, keys, chunk_iter)
10241023
# GH 46891
1025-
if is_integer(num_inserted):
1026-
num_inserted = int(num_inserted)
1024+
if num_inserted is not None:
10271025
if total_inserted is None:
10281026
total_inserted = num_inserted
10291027
else:

pandas/util/_validators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def validate_bool_kwarg(
260260
f'For argument "{arg_name}" expected type bool, received '
261261
f"type {type(value).__name__}."
262262
)
263-
return value # pyright: ignore[reportGeneralTypeIssues]
263+
return value
264264

265265

266266
def validate_fillna_kwargs(value, method, validate_scalar_dict_value: bool = True):

0 commit comments

Comments
 (0)