-
-
Notifications
You must be signed in to change notification settings - Fork 154
Type DataFrame methods: __setitem__, asof, set_axis
#1473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0b17616
a05e17f
b66d0c8
c0f4536
6c91caa
9538b55
02f940a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,7 @@ from pandas import ( | |||||||
| Timestamp, | ||||||||
| ) | ||||||||
| from pandas.core.arraylike import OpsMixin | ||||||||
| from pandas.core.base import IndexOpsMixin | ||||||||
| from pandas.core.generic import NDFrame | ||||||||
| from pandas.core.groupby.generic import DataFrameGroupBy | ||||||||
| from pandas.core.indexers import BaseIndexer | ||||||||
|
|
@@ -92,6 +93,7 @@ from pandas._typing import ( | |||||||
| ArrayLike, | ||||||||
| AstypeArg, | ||||||||
| Axes, | ||||||||
| AxesData, | ||||||||
| Axis, | ||||||||
| AxisColumn, | ||||||||
| AxisIndex, | ||||||||
|
|
@@ -197,6 +199,8 @@ class _iLocIndexerFrame(_iLocIndexer, Generic[_T]): | |||||||
| | tuple[slice] | ||||||||
| ), | ||||||||
| ) -> _T: ... | ||||||||
|
|
||||||||
| # Keep in sync with `DataFrame.__setitem__` | ||||||||
| def __setitem__( | ||||||||
| self, | ||||||||
| idx: ( | ||||||||
|
|
@@ -209,7 +213,7 @@ class _iLocIndexerFrame(_iLocIndexer, Generic[_T]): | |||||||
| ), | ||||||||
| value: ( | ||||||||
| Scalar | ||||||||
| | Series | ||||||||
| | IndexOpsMixin | ||||||||
| | DataFrame | ||||||||
| | np_ndarray | ||||||||
| | NAType | ||||||||
|
|
@@ -273,6 +277,8 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]): | |||||||
| ) -> Series: ... | ||||||||
| @overload | ||||||||
| def __getitem__(self, idx: tuple[Scalar, slice]) -> Series | _T: ... | ||||||||
|
|
||||||||
| # Keep in sync with `DataFrame.__setitem__` | ||||||||
| @overload | ||||||||
| def __setitem__( | ||||||||
| self, | ||||||||
|
|
@@ -284,7 +290,7 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]): | |||||||
| | NAType | ||||||||
| | NaTType | ||||||||
| | ArrayLike | ||||||||
| | Series | ||||||||
| | IndexOpsMixin | ||||||||
| | DataFrame | ||||||||
| | list | ||||||||
| | Mapping[Hashable, Scalar | NAType | NaTType] | ||||||||
|
|
@@ -328,7 +334,7 @@ class _AtIndexerFrame(_AtIndexer): | |||||||
| | NAType | ||||||||
| | NaTType | ||||||||
| | ArrayLike | ||||||||
| | Series | ||||||||
| | IndexOpsMixin | ||||||||
| | DataFrame | ||||||||
| | list | ||||||||
| | Mapping[Hashable, Scalar | NAType | NaTType] | ||||||||
|
|
@@ -800,7 +806,74 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): | |||||||
| def isetitem( | ||||||||
| self, loc: int | Sequence[int], value: Scalar | ArrayLike | list[Any] | ||||||||
| ) -> None: ... | ||||||||
| def __setitem__(self, key, value) -> None: ... | ||||||||
|
|
||||||||
| # Keep in sync with `_iLocIndexerFrame.__setitem__` | ||||||||
| @overload | ||||||||
| def __setitem__( | ||||||||
| self, | ||||||||
| idx: ( | ||||||||
| int | ||||||||
| | IndexType | ||||||||
| | tuple[int, int] | ||||||||
| | tuple[IndexType, int] | ||||||||
| | tuple[IndexType, IndexType] | ||||||||
| | tuple[int, IndexType] | ||||||||
| ), | ||||||||
| value: ( | ||||||||
| Scalar | ||||||||
| | IndexOpsMixin | ||||||||
| | Sequence[Scalar] | ||||||||
| | DataFrame | ||||||||
| | np.ndarray | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| | NAType | ||||||||
| | NaTType | ||||||||
| | Mapping[Hashable, Scalar | NAType | NaTType] | ||||||||
| | None | ||||||||
| ), | ||||||||
| ) -> None: ... | ||||||||
| # Keep in sync with `_LocIndexerFrame.__setitem__` | ||||||||
| @overload | ||||||||
| def __setitem__( | ||||||||
| self, | ||||||||
| idx: ( | ||||||||
| MaskType | StrLike | _IndexSliceTuple | list[ScalarT] | IndexingInt | slice | ||||||||
cmp0xff marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| ), | ||||||||
| value: ( | ||||||||
| Scalar | ||||||||
| | NAType | ||||||||
| | NaTType | ||||||||
| | ArrayLike | ||||||||
| | IndexOpsMixin | ||||||||
| | Sequence[Scalar] | ||||||||
| | DataFrame | ||||||||
| | list | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why extra
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because without it df[["col1", "col2"]] = [[1, 2], [3, 4]]would raise, as
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following works >>> import pandas as pd
>>> df = pd.DataFrame(columns=["a", 'b'])
>>> df[["a", "b"]] = ((1, 2), (3, 4))so maybe
Suggested change
|
||||||||
| | Mapping[Hashable, Scalar | NAType | NaTType] | ||||||||
| | None | ||||||||
| ), | ||||||||
| ) -> None: ... | ||||||||
| @overload | ||||||||
| def __setitem__( | ||||||||
| self, | ||||||||
| idx: tuple[_IndexSliceTuple, Hashable], | ||||||||
| value: ( | ||||||||
| Scalar | ||||||||
| | NAType | ||||||||
| | NaTType | ||||||||
| | ArrayLike | ||||||||
| | IndexOpsMixin | ||||||||
| | Sequence[Scalar] | ||||||||
| | dict | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it be the following?
Suggested change
|
||||||||
| | None | ||||||||
| ), | ||||||||
| ) -> None: ... | ||||||||
| # Extra cases not supported by `_LocIndexerFrame.__setitem__` / | ||||||||
| # `_iLocIndexerFrame.__setitem__`. | ||||||||
| @overload | ||||||||
| def __setitem__( | ||||||||
| self, | ||||||||
| idx: IndexOpsMixin | DataFrame, | ||||||||
| value: Scalar | NAType | NaTType | ArrayLike | Series | list | dict | None, | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it be something like the following?
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the dict part sure, the list part i don't think so #1473 (comment) |
||||||||
| ): ... | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| @overload | ||||||||
| def query( | ||||||||
| self, | ||||||||
|
|
@@ -1917,7 +1990,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): | |||||||
| **kwargs: Any, | ||||||||
| ) -> Series[_bool]: ... | ||||||||
| @final | ||||||||
| def asof(self, where, subset: _str | list[_str] | None = None) -> Self: ... | ||||||||
| def asof( | ||||||||
| self, | ||||||||
| where: Scalar | AnyArrayLike | Sequence[Scalar], | ||||||||
| subset: Hashable | list[Hashable] | None = None, | ||||||||
cmp0xff marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| ) -> Self: ... | ||||||||
| @final | ||||||||
| def asfreq( | ||||||||
| self, | ||||||||
|
|
@@ -2454,7 +2531,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): | |||||||
| **kwargs: Any, | ||||||||
| ) -> Series: ... | ||||||||
| # Not actually positional, but used to handle removal of deprecated | ||||||||
| def set_axis(self, labels, *, axis: Axis = ..., copy: _bool = ...) -> Self: ... | ||||||||
| def set_axis( | ||||||||
| self, labels: AxesData, *, axis: Axis = 0, copy: _bool = ... | ||||||||
| ) -> Self: ... | ||||||||
| def skew( | ||||||||
| self, | ||||||||
| axis: Axis | None = ..., | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ from typing import ( | |||||
| TypeVar, | ||||||
| ) | ||||||
|
|
||||||
| from pandas.core.indexes.api import Index | ||||||
| from pandas.core.base import IndexOpsMixin | ||||||
|
|
||||||
| from pandas._libs.indexing import _NDFrameIndexerBase | ||||||
| from pandas._typing import ( | ||||||
|
|
@@ -13,7 +13,7 @@ from pandas._typing import ( | |||||
| ) | ||||||
|
|
||||||
| _IndexSliceTuple: TypeAlias = tuple[ | ||||||
| Index | MaskType | Scalar | list[ScalarT] | slice | tuple[Scalar, ...], ... | ||||||
| IndexOpsMixin | MaskType | Scalar | list[ScalarT] | slice | tuple[Scalar, ...], ... | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it be the following?
Suggested change
|
||||||
| ] | ||||||
|
|
||||||
| _IndexSliceUnion: TypeAlias = slice | _IndexSliceTuple | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.