Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ from pandas.core.indexes.multi import MultiIndex
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.indexing import (
_AtIndexer,
_iAtIndexer,
_iLocIndexer,
_IndexSliceTuple,
_LocIndexer,
Expand Down Expand Up @@ -285,6 +287,44 @@ class _LocIndexerFrame(_LocIndexer, Generic[_T]):
value: Scalar | NAType | NaTType | ArrayLike | Series | list | dict | None,
) -> None: ...

class _iAtIndexerFrame(_iAtIndexer, Generic[_T]):
def __getitem__(self, idx: tuple[int, int]) -> Scalar: ...
def __setitem__(
self,
idx: tuple[int, int],
value: Scalar | NAType | NaTType | None,
) -> None: ...

class _AtIndexerFrame(_AtIndexer, Generic[_T]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since none of the methods in either of these refer to _T, you can remove the Generic part.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I had duplicated the _LocIndexerFrame and was removing unused section but forgot about it.

def __getitem__(
self,
idx: tuple[
int
| StrLike
| Timestamp
| tuple[Scalar, ...]
| Callable[[DataFrame], ScalarT],
int | StrLike | tuple[Scalar, ...],
],
) -> Scalar: ...
def __setitem__(
self,
idx: (
MaskType | StrLike | _IndexSliceTuple | list[ScalarT] | IndexingInt | slice
),
value: (
Scalar
| NAType
| NaTType
| ArrayLike
| Series
| DataFrame
| list
| Mapping[Hashable, Scalar | NAType | NaTType]
| None
),
) -> None: ...

# With mypy 1.14.1 and python 3.12, the second overload needs a type-ignore statement
if sys.version_info >= (3, 12):
class _GetItemHack:
Expand Down Expand Up @@ -1591,13 +1631,13 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
axis: Axis = 0,
skipna: _bool = True,
numeric_only: _bool = False,
) -> Series: ...
) -> Series[int]: ...
def idxmin(
self,
axis: Axis = 0,
skipna: _bool = True,
numeric_only: _bool = False,
) -> Series: ...
) -> Series[int]: ...
def mode(
self,
axis: Axis = 0,
Expand Down Expand Up @@ -1683,7 +1723,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
def __iter__(self) -> Iterator[Hashable]: ...
# properties
@property
def at(self): ... # Not sure what to do with this yet; look at source
def at(
self,
) -> _AtIndexerFrame: ... # Not sure what to do with this yet; look at source
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comment

@property
def columns(self) -> Index[str]: ...
@columns.setter # setter needs to be right next to getter; otherwise mypy complains
Expand All @@ -1695,7 +1737,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
@property
def empty(self) -> _bool: ...
@property
def iat(self): ... # Not sure what to do with this yet; look at source
def iat(
self,
) -> _iAtIndexerFrame: ... # Not sure what to do with this yet; look at source
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comment

@property
def iloc(self) -> _iLocIndexerFrame[Self]: ...
@property
Expand Down
6 changes: 3 additions & 3 deletions pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ from pandas.core.dtypes.dtypes import DatetimeTZDtype
from pandas.tseries.offsets import BaseOffset

class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
def __init__(
self,
def __new__(
cls,
data: AxesData,
freq: Frequency = ...,
tz: TimeZones = ...,
Expand All @@ -55,7 +55,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
dtype: Dtype = ...,
copy: bool = ...,
name: Hashable = ...,
) -> None: ...
) -> Self: ...
def __reduce__(self): ...
# various ignores needed for mypy, as we do want to restrict what can be used in
# arithmetic for these types
Expand Down
Loading
Loading