Skip to content

Commit c2b80ff

Browse files
FIX: type-var for idx in Series.loc.__setitem__(...) (#1670)
* Fix type-var for `idx` in `Series.loc.__setitem__(...)` Fixes #1669 . * TST: GH1669 Add testing to `Series.loc.__setitem__` when element types don't match * Fix newly added part in `test_series_loc_setitem` so that it could be runnable * Change `IndexOpsMixin[Any]` to `IndexOpsMixin` Co-authored-by: Yi-Fan Wang <cmp0xff@users.noreply.github.com> --------- Co-authored-by: Yi-Fan Wang <cmp0xff@users.noreply.github.com>
1 parent 6bc10ad commit c2b80ff

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class _LocIndexerSeries(_LocIndexer, Generic[S1]):
317317
@overload
318318
def __setitem__(
319319
self,
320-
idx: IndexOpsMixin[S1] | MaskType | slice,
320+
idx: IndexOpsMixin | MaskType | slice,
321321
value: S1 | ArrayLike | IndexOpsMixin[S1] | None,
322322
) -> None: ...
323323
@overload

tests/series/test_indexing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ def test_series_loc_setitem() -> None:
9393
v = s.loc[[0, 2, 4]].values
9494
s.loc[[0, 2, 4]] = v
9595

96+
# GH 1669
97+
s = pd.Series([1, 2, 3, 4, 5], index=["a", "b", "c", "d", "e"])
98+
idx = pd.Index(["a", "c", "e"])
99+
v = s.loc[idx].values
100+
s.loc[idx] = v
101+
96102

97103
def test_series_isin() -> None:
98104
s = pd.Series([1, 2, 3, 4, 5])

0 commit comments

Comments
 (0)