Skip to content

Commit 1b6e4c7

Browse files
GH1139 PR Feedback
1 parent d65a325 commit 1b6e4c7

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pandas-stubs/core/series.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
10411041
broadcast_axis: AxisIndex | None = ...,
10421042
) -> tuple[Series, Series]: ...
10431043
@overload
1044-
def rename( # pyright: ignore[reportOverlappingOverload]
1044+
def rename(
10451045
self,
1046-
index: Hashable = ...,
1046+
index: Hashable,
10471047
*,
10481048
axis: Axis | None = ...,
10491049
copy: bool = ...,
@@ -1052,7 +1052,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
10521052
errors: IgnoreRaise = ...,
10531053
) -> Self: ...
10541054
@overload
1055-
def rename( # type: ignore[overload-cannot-match]
1055+
def rename(
10561056
self,
10571057
index: Renamer | None = ...,
10581058
*,

tests/test_series.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ def test_types_set_flags() -> None:
11381138

11391139
def test_types_getitem() -> None:
11401140
s = pd.Series({"key": [0, 1, 2, 3]})
1141+
check(assert_type(s["key"], Any), list)
11411142
s2 = pd.Series([0, 1, 2, 3])
11421143
check(assert_type(s2[0], int), np.integer)
11431144
check(assert_type(s[:2], pd.Series), pd.Series)
@@ -1227,11 +1228,19 @@ def add1(x: int) -> int:
12271228
s5 = pd.Series([1, 2, 3]).rename({1: 10})
12281229
check(assert_type(s5, "pd.Series[int]"), pd.Series, np.integer)
12291230
# inplace
1230-
# TODO fix issue with inplace=True returning a Series, cf pandas #60942
12311231
check(
12321232
assert_type(pd.Series([1, 2, 3]).rename("A", inplace=True), "pd.Series[int]"),
12331233
pd.Series,
1234+
np.integer,
1235+
)
1236+
check(
1237+
assert_type(pd.Series([1, 2, 3]).rename({1: 4, 2: 5}, inplace=True), None),
1238+
type(None),
12341239
)
1240+
# TODO this should not raise an error, the lambda is matched with Hashable
1241+
# check(
1242+
# assert_type(pd.Series([1, 2, 3]).rename(lambda x: x**2, inplace=True), None), type(None)
1243+
# )
12351244

12361245
if TYPE_CHECKING_INVALID_USAGE:
12371246
s7 = pd.Series([1, 2, 3]).rename({1: [3, 4, 5]}) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]

0 commit comments

Comments
 (0)