Skip to content

Add check assert_type to tests for frame.py and add __new__ method for DatetimeIndex #1313

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

Merged
merged 4 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 44 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):
def __getitem__(self, idx: tuple[int, int]) -> Scalar: ...
def __setitem__(
self,
idx: tuple[int, int],
value: Scalar | NAType | NaTType | None,
) -> None: ...

class _AtIndexerFrame(_AtIndexer):
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,7 @@ 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: ...
@property
def columns(self) -> Index[str]: ...
@columns.setter # setter needs to be right next to getter; otherwise mypy complains
Expand All @@ -1695,7 +1735,7 @@ 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: ...
@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