Skip to content

Commit a05e17f

Browse files
committed
type setitem
1 parent 0b17616 commit a05e17f

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ from pandas import (
3737
Timestamp,
3838
)
3939
from pandas.core.arraylike import OpsMixin
40+
from pandas.core.base import IndexOpsMixin
4041
from pandas.core.generic import NDFrame
4142
from pandas.core.groupby.generic import DataFrameGroupBy
4243
from pandas.core.indexers import BaseIndexer
@@ -90,6 +91,7 @@ from pandas._typing import (
9091
ArrayLike,
9192
AstypeArg,
9293
Axes,
94+
AxesData,
9395
Axis,
9496
AxisColumn,
9597
AxisIndex,
@@ -191,6 +193,8 @@ class _iLocIndexerFrame(_iLocIndexer, Generic[_T]):
191193
| tuple[slice]
192194
),
193195
) -> _T: ...
196+
197+
# Keep in sync with `DataFrame.__setitem__`
194198
def __setitem__(
195199
self,
196200
idx: (
@@ -203,7 +207,7 @@ class _iLocIndexerFrame(_iLocIndexer, Generic[_T]):
203207
),
204208
value: (
205209
Scalar
206-
| Series
210+
| IndexOpsMixin
207211
| DataFrame
208212
| np.ndarray
209213
| NAType
@@ -267,6 +271,8 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]):
267271
) -> Series: ...
268272
@overload
269273
def __getitem__(self, idx: tuple[Scalar, slice]) -> Series | _T: ...
274+
275+
# Keep in sync with `DataFrame.__setitem__`
270276
@overload
271277
def __setitem__(
272278
self,
@@ -278,7 +284,7 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]):
278284
| NAType
279285
| NaTType
280286
| ArrayLike
281-
| Series
287+
| IndexOpsMixin
282288
| DataFrame
283289
| list
284290
| Mapping[Hashable, Scalar | NAType | NaTType]
@@ -322,7 +328,7 @@ class _AtIndexerFrame(_AtIndexer):
322328
| NAType
323329
| NaTType
324330
| ArrayLike
325-
| Series
331+
| IndexOpsMixin
326332
| DataFrame
327333
| list
328334
| Mapping[Hashable, Scalar | NAType | NaTType]
@@ -794,7 +800,57 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
794800
def isetitem(
795801
self, loc: int | Sequence[int], value: Scalar | ArrayLike | list[Any]
796802
) -> None: ...
797-
def __setitem__(self, key, value) -> None: ...
803+
804+
# Keep in sync with `_iLocIndexerFrame.__setitem__`
805+
@overload
806+
def __setitem__(
807+
self,
808+
idx: (
809+
int
810+
| IndexType
811+
| tuple[int, int]
812+
| tuple[IndexType, int]
813+
| tuple[IndexType, IndexType]
814+
| tuple[int, IndexType]
815+
),
816+
value: (
817+
Scalar
818+
| IndexOpsMixin
819+
| DataFrame
820+
| np.ndarray
821+
| NAType
822+
| NaTType
823+
| Mapping[Hashable, Scalar | NAType | NaTType]
824+
| None
825+
),
826+
) -> None: ...
827+
# Keep in sync with `_LocIndexerFrame.__setitem__`
828+
@overload
829+
def __setitem__(
830+
self,
831+
idx: (
832+
MaskType | StrLike | _IndexSliceTuple | list[ScalarT] | IndexingInt | slice
833+
),
834+
value: (
835+
Scalar
836+
| NAType
837+
| NaTType
838+
| ArrayLike
839+
| IndexOpsMixin
840+
| DataFrame
841+
| list
842+
| Mapping[Hashable, Scalar | NAType | NaTType]
843+
| None
844+
),
845+
) -> None: ...
846+
@overload
847+
def __setitem__(
848+
self,
849+
idx: tuple[_IndexSliceTuple, Hashable],
850+
value: (
851+
Scalar | NAType | NaTType | ArrayLike | IndexOpsMixin | list | dict | None
852+
),
853+
) -> None: ...
798854
@overload
799855
def query(
800856
self,
@@ -2398,7 +2454,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23982454
**kwargs: Any,
23992455
) -> Series: ...
24002456
# Not actually positional, but used to handle removal of deprecated
2401-
def set_axis(self, labels, *, axis: Axis = ..., copy: _bool = ...) -> Self: ...
2457+
def set_axis(
2458+
self, labels: AxesData, *, axis: Axis = 0, copy: _bool = ...
2459+
) -> Self: ...
24022460
def skew(
24032461
self,
24042462
axis: Axis | None = ...,

pandas-stubs/core/series.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,14 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
535535
@final
536536
def __getattr__(self, name: _str) -> S1: ...
537537

538-
# Keep in sync with `iLocIndexerSeries.__getitem__`
538+
# Keep in sync with `_iLocIndexerSeries.__getitem__`
539539
@overload
540540
def __getitem__(self, idx: IndexingInt) -> S1: ...
541541
@overload
542542
def __getitem__(
543543
self, idx: Index | Series | slice | np_ndarray_anyint
544544
) -> Series[S1]: ...
545-
# Keep in sync with `LocIndexerSeries.__getitem__`
545+
# Keep in sync with `_LocIndexerSeries.__getitem__`
546546
@overload
547547
def __getitem__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
548548
self,

0 commit comments

Comments
 (0)