Skip to content

Commit 1f50233

Browse files
committed
more compatibility with pandas-stub tests
1 parent 3e45b41 commit 1f50233

File tree

11 files changed

+52
-75
lines changed

11 files changed

+52
-75
lines changed

pandas/_testing/asserters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ def assert_series_equal(
865865
left,
866866
right,
867867
check_dtype: bool | Literal["equiv"] = True,
868-
check_index_type="equiv",
868+
check_index_type: bool | Literal["equiv"] = "equiv",
869869
check_series_type=True,
870870
check_less_precise: bool | int | NoDefault = no_default,
871871
check_names=True,
@@ -1133,7 +1133,7 @@ def assert_frame_equal(
11331133
left,
11341134
right,
11351135
check_dtype: bool | Literal["equiv"] = True,
1136-
check_index_type="equiv",
1136+
check_index_type: bool | Literal["equiv"] = "equiv",
11371137
check_column_type="equiv",
11381138
check_frame_type=True,
11391139
check_less_precise=no_default,

pandas/core/arrays/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def equals(self, other: object) -> bool:
985985
equal_na = self.isna() & other.isna() # type: ignore[operator]
986986
return bool((equal_values | equal_na).all())
987987

988-
def isin(self, values) -> np.ndarray:
988+
def isin(self, values) -> npt.NDArray[np.bool_]:
989989
"""
990990
Pointwise comparison for set containment in the given values.
991991

pandas/core/arrays/interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ def contains(self, other):
17371737
other < self._right if self.open_right else other <= self._right
17381738
)
17391739

1740-
def isin(self, values) -> np.ndarray:
1740+
def isin(self, values) -> npt.NDArray[np.bool_]:
17411741
if not hasattr(values, "dtype"):
17421742
values = np.array(values)
17431743
values = extract_array(values, extract_numpy=True)

pandas/core/arrays/string_arrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _maybe_convert_setitem_value(self, value):
202202
raise ValueError("Scalar must be NA or str")
203203
return value
204204

205-
def isin(self, values):
205+
def isin(self, values) -> npt.NDArray[np.bool_]:
206206
if pa_version_under2p0:
207207
fallback_performancewarning(version="2")
208208
return super().isin(values)

pandas/core/frame.py

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5996,7 +5996,8 @@ def set_index(
59965996
@overload
59975997
def reset_index(
59985998
self,
5999-
level: Hashable | Sequence[Hashable] | None = ...,
5999+
level: IndexLabel = ...,
6000+
*,
60006001
drop: bool = ...,
60016002
inplace: Literal[False] = ...,
60026003
col_level: Hashable = ...,
@@ -6009,34 +6010,9 @@ def reset_index(
60096010
@overload
60106011
def reset_index(
60116012
self,
6012-
level: Hashable | Sequence[Hashable] | None,
6013-
drop: bool,
6014-
inplace: Literal[True],
6015-
col_level: Hashable = ...,
6016-
col_fill: Hashable = ...,
6017-
allow_duplicates: bool | lib.NoDefault = ...,
6018-
names: Hashable | Sequence[Hashable] = None,
6019-
) -> None:
6020-
...
6021-
6022-
@overload
6023-
def reset_index(
6024-
self,
6025-
*,
6026-
drop: bool,
6027-
inplace: Literal[True],
6028-
col_level: Hashable = ...,
6029-
col_fill: Hashable = ...,
6030-
allow_duplicates: bool | lib.NoDefault = ...,
6031-
names: Hashable | Sequence[Hashable] = None,
6032-
) -> None:
6033-
...
6034-
6035-
@overload
6036-
def reset_index(
6037-
self,
6038-
level: Hashable | Sequence[Hashable] | None,
6013+
level: IndexLabel = ...,
60396014
*,
6015+
drop: bool = ...,
60406016
inplace: Literal[True],
60416017
col_level: Hashable = ...,
60426018
col_fill: Hashable = ...,
@@ -6048,19 +6024,8 @@ def reset_index(
60486024
@overload
60496025
def reset_index(
60506026
self,
6027+
level: IndexLabel = ...,
60516028
*,
6052-
inplace: Literal[True],
6053-
col_level: Hashable = ...,
6054-
col_fill: Hashable = ...,
6055-
allow_duplicates: bool | lib.NoDefault = ...,
6056-
names: Hashable | Sequence[Hashable] = None,
6057-
) -> None:
6058-
...
6059-
6060-
@overload
6061-
def reset_index(
6062-
self,
6063-
level: Hashable | Sequence[Hashable] | None = ...,
60646029
drop: bool = ...,
60656030
inplace: bool = ...,
60666031
col_level: Hashable = ...,
@@ -6073,7 +6038,7 @@ def reset_index(
60736038
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "level"])
60746039
def reset_index(
60756040
self,
6076-
level: Hashable | Sequence[Hashable] | None = None,
6041+
level: IndexLabel = None,
60776042
drop: bool = False,
60786043
inplace: bool = False,
60796044
col_level: Hashable = 0,
@@ -6532,7 +6497,7 @@ def dropna(
65326497
def drop_duplicates(
65336498
self,
65346499
subset: Hashable | Sequence[Hashable] | None = None,
6535-
keep: Literal["first"] | Literal["last"] | Literal[False] = "first",
6500+
keep: Literal["first", "last", False] = "first",
65366501
inplace: bool = False,
65376502
ignore_index: bool = False,
65386503
) -> DataFrame | None:
@@ -6629,7 +6594,7 @@ def drop_duplicates(
66296594
def duplicated(
66306595
self,
66316596
subset: Hashable | Sequence[Hashable] | None = None,
6632-
keep: Literal["first"] | Literal["last"] | Literal[False] = "first",
6597+
keep: Literal["first", "last", False] = "first",
66336598
) -> Series:
66346599
"""
66356600
Return boolean Series denoting duplicate rows.
@@ -6892,7 +6857,7 @@ def sort_index(
68926857
self,
68936858
*,
68946859
axis: Axis = ...,
6895-
level: Level = ...,
6860+
level: IndexLabel = ...,
68966861
ascending: bool | Sequence[bool] = ...,
68976862
inplace: Literal[True],
68986863
kind: SortKind = ...,
@@ -6908,7 +6873,7 @@ def sort_index(
69086873
self,
69096874
*,
69106875
axis: Axis = ...,
6911-
level: Level = ...,
6876+
level: IndexLabel = ...,
69126877
ascending: bool | Sequence[bool] = ...,
69136878
inplace: Literal[False] = ...,
69146879
kind: SortKind = ...,
@@ -6924,7 +6889,7 @@ def sort_index(
69246889
self,
69256890
*,
69266891
axis: Axis = ...,
6927-
level: Level = ...,
6892+
level: IndexLabel = ...,
69286893
ascending: bool | Sequence[bool] = ...,
69296894
inplace: bool = ...,
69306895
kind: SortKind = ...,
@@ -6940,7 +6905,7 @@ def sort_index(
69406905
def sort_index( # type: ignore[override]
69416906
self,
69426907
axis: Axis = 0,
6943-
level: Level = None,
6908+
level: IndexLabel = None,
69446909
ascending: bool | Sequence[bool] = True,
69456910
inplace: bool = False,
69466911
kind: SortKind = "quicksort",

pandas/core/generic.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,7 +3192,7 @@ def to_latex(
31923192
multicolumn: bool_t | None = ...,
31933193
multicolumn_format: str | None = ...,
31943194
multirow: bool_t | None = ...,
3195-
caption: str | None = ...,
3195+
caption: str | tuple[str, str] | None = ...,
31963196
label: str | None = ...,
31973197
position: str | None = ...,
31983198
) -> str:
@@ -3220,7 +3220,7 @@ def to_latex(
32203220
multicolumn: bool_t | None = ...,
32213221
multicolumn_format: str | None = ...,
32223222
multirow: bool_t | None = ...,
3223-
caption: str | None = ...,
3223+
caption: str | tuple[str, str] | None = ...,
32243224
label: str | None = ...,
32253225
position: str | None = ...,
32263226
) -> None:
@@ -3249,7 +3249,7 @@ def to_latex(
32493249
multicolumn: bool_t | None = None,
32503250
multicolumn_format: str | None = None,
32513251
multirow: bool_t | None = None,
3252-
caption: str | None = None,
3252+
caption: str | tuple[str, str] | None = None,
32533253
label: str | None = None,
32543254
position: str | None = None,
32553255
) -> str | None:
@@ -4882,7 +4882,7 @@ def sort_index(
48824882
self,
48834883
*,
48844884
axis: Axis = ...,
4885-
level: Level | None = ...,
4885+
level: IndexLabel = ...,
48864886
ascending: bool_t | Sequence[bool_t] = ...,
48874887
inplace: Literal[True],
48884888
kind: SortKind = ...,
@@ -4898,7 +4898,7 @@ def sort_index(
48984898
self: NDFrameT,
48994899
*,
49004900
axis: Axis = ...,
4901-
level: Level | None = ...,
4901+
level: IndexLabel = ...,
49024902
ascending: bool_t | Sequence[bool_t] = ...,
49034903
inplace: Literal[False] = ...,
49044904
kind: SortKind = ...,
@@ -4914,7 +4914,7 @@ def sort_index(
49144914
self: NDFrameT,
49154915
*,
49164916
axis: Axis = ...,
4917-
level: Level | None = ...,
4917+
level: IndexLabel = ...,
49184918
ascending: bool_t | Sequence[bool_t] = ...,
49194919
inplace: bool_t = ...,
49204920
kind: SortKind = ...,
@@ -4928,7 +4928,7 @@ def sort_index(
49284928
def sort_index(
49294929
self: NDFrameT,
49304930
axis: Axis = 0,
4931-
level: Level | None = None,
4931+
level: IndexLabel = None,
49324932
ascending: bool_t | Sequence[bool_t] = True,
49334933
inplace: bool_t = False,
49344934
kind: SortKind = "quicksort",

pandas/core/groupby/groupby.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,9 @@ def size(self) -> DataFrame | Series:
24012401
result = self._obj_1d_constructor(result)
24022402

24032403
if not self.as_index:
2404-
result = result.rename("size").reset_index()
2404+
# error: Incompatible types in assignment (expression has
2405+
# type "DataFrame", variable has type "Series")
2406+
result = result.rename("size").reset_index() # type: ignore[assignment]
24052407

24062408
return self._reindex_output(result, fill_value=0)
24072409

pandas/core/indexes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6425,7 +6425,7 @@ def _transform_index(self, func, *, level=None) -> Index:
64256425
items = [func(x) for x in self]
64266426
return Index(items, name=self.name, tupleize_cols=False)
64276427

6428-
def isin(self, values, level=None) -> np.ndarray:
6428+
def isin(self, values, level=None) -> npt.NDArray[np.bool_]:
64296429
"""
64306430
Return a boolean array where the index values are in `values`.
64316431

pandas/core/series.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,21 @@ def repeat(self, repeats: int | Sequence[int], axis: None = None) -> Series:
13801380
@overload
13811381
def reset_index(
13821382
self,
1383-
level: Level = ...,
1383+
level: IndexLabel = ...,
13841384
*,
1385-
drop: bool = ...,
1385+
drop: Literal[False] = ...,
1386+
name: Level = ...,
1387+
inplace: Literal[False] = ...,
1388+
allow_duplicates: bool = ...,
1389+
) -> DataFrame:
1390+
...
1391+
1392+
@overload
1393+
def reset_index(
1394+
self,
1395+
level: IndexLabel = ...,
1396+
*,
1397+
drop: Literal[True],
13861398
name: Level = ...,
13871399
inplace: Literal[False] = ...,
13881400
allow_duplicates: bool = ...,
@@ -1392,7 +1404,7 @@ def reset_index(
13921404
@overload
13931405
def reset_index(
13941406
self,
1395-
level: Level = ...,
1407+
level: IndexLabel = ...,
13961408
*,
13971409
drop: bool = ...,
13981410
name: Level = ...,
@@ -1404,12 +1416,12 @@ def reset_index(
14041416
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "level"])
14051417
def reset_index(
14061418
self,
1407-
level: Level = None,
1419+
level: IndexLabel = None,
14081420
drop: bool = False,
14091421
name: Level = lib.no_default,
14101422
inplace: bool = False,
14111423
allow_duplicates: bool = False,
1412-
) -> Series | None:
1424+
) -> DataFrame | Series | None:
14131425
"""
14141426
Generate a new DataFrame or Series with the index reset.
14151427
@@ -1554,9 +1566,7 @@ def reset_index(
15541566
name = self.name
15551567

15561568
df = self.to_frame(name)
1557-
# error: Incompatible return value type (got "DataFrame", expected
1558-
# "Optional[Series]")
1559-
return df.reset_index( # type: ignore[return-value]
1569+
return df.reset_index(
15601570
level=level, drop=drop, allow_duplicates=allow_duplicates
15611571
)
15621572
return None
@@ -3741,7 +3751,7 @@ def sort_index(
37413751
self,
37423752
*,
37433753
axis: Axis = ...,
3744-
level: Level | None = ...,
3754+
level: IndexLabel = ...,
37453755
ascending: bool | Sequence[bool] = ...,
37463756
inplace: Literal[True],
37473757
kind: SortKind = ...,
@@ -3757,7 +3767,7 @@ def sort_index(
37573767
self,
37583768
*,
37593769
axis: Axis = ...,
3760-
level: Level | None = ...,
3770+
level: IndexLabel = ...,
37613771
ascending: bool | Sequence[bool] = ...,
37623772
inplace: Literal[False] = ...,
37633773
kind: SortKind = ...,
@@ -3773,7 +3783,7 @@ def sort_index(
37733783
self,
37743784
*,
37753785
axis: Axis = ...,
3776-
level: Level | None = ...,
3786+
level: IndexLabel = ...,
37773787
ascending: bool | Sequence[bool] = ...,
37783788
inplace: bool = ...,
37793789
kind: SortKind = ...,
@@ -3789,7 +3799,7 @@ def sort_index(
37893799
def sort_index( # type: ignore[override]
37903800
self,
37913801
axis: Axis = 0,
3792-
level: Level | None = None,
3802+
level: IndexLabel = None,
37933803
ascending: bool | Sequence[bool] = True,
37943804
inplace: bool = False,
37953805
kind: SortKind = "quicksort",

pandas/io/excel/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
def read_excel(
358358
io,
359359
# sheet name is str or int -> DataFrame
360-
sheet_name: str | int,
360+
sheet_name: str | int = ...,
361361
header: int | Sequence[int] | None = ...,
362362
names: list[str] | None = ...,
363363
index_col: int | Sequence[int] | None = ...,

pandas/io/formats/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ def to_latex(
10361036
multicolumn: bool = False,
10371037
multicolumn_format: str | None = None,
10381038
multirow: bool = False,
1039-
caption: str | None = None,
1039+
caption: str | tuple[str, str] | None = None,
10401040
label: str | None = None,
10411041
position: str | None = None,
10421042
) -> str | None:

0 commit comments

Comments
 (0)