diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 0c397e46f..ca8d7bbdd 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -170,6 +170,7 @@ class DataFrame(NDFrame, OpsMixin): __hash__: ClassVar[None] # type: ignore[assignment] + @overload def __new__( cls, data: ListLikeU @@ -182,6 +183,15 @@ class DataFrame(NDFrame, OpsMixin): dtype=..., copy: _bool = ..., ) -> DataFrame: ... + @overload + def __new__( + cls, + data: Scalar, + index: Axes, + columns: Axes, + dtype=..., + copy: _bool = ..., + ) -> DataFrame: ... @property def axes(self) -> list[Index]: ... @property diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 07018808d..cf45b3e5d 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -122,14 +122,14 @@ class _LocIndexerSeries(_LocIndexer, Generic[S1]): idx: MaskType | Index | Sequence[float] - | list[_str] + | list[str] | slice | tuple[str | float | slice | Index, ...], ) -> Series[S1]: ... @overload def __getitem__( self, - idx: _str | float, + idx: str | float, ) -> S1: ... @overload def __setitem__( @@ -159,7 +159,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): def __new__( cls, data: DatetimeIndex, - index: _str | int | Series | list | Index | None = ..., + index: Axes | None = ..., dtype=..., name: Hashable | None = ..., copy: bool = ..., @@ -169,7 +169,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): def __new__( cls, data: PeriodIndex, - index: _str | int | Series | list | Index | None = ..., + index: Axes | None = ..., dtype=..., name: Hashable | None = ..., copy: bool = ..., @@ -180,7 +180,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): cls, data: object | _ListLike | Series[S1] | dict[int, S1] | dict[_str, S1] | None, dtype: type[S1], - index: _str | int | Series | list | Index | None = ..., + index: Axes | None = ..., name: Hashable | None = ..., copy: bool = ..., fastpath: bool = ..., @@ -194,7 +194,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): | dict[int, S1] | dict[_str, S1] | None = ..., - index: _str | int | Series | list | Index | None = ..., + index: Axes | None = ..., dtype=..., name: Hashable | None = ..., copy: bool = ..., diff --git a/tests/test_frame.py b/tests/test_frame.py index 8aed66021..1a37e083a 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -42,6 +42,10 @@ def test_types_init() -> None: dtype=np.int8, copy=True, ) + check( + assert_type(pd.DataFrame(0, index=[0, 1], columns=[0, 1]), pd.DataFrame), + pd.DataFrame, + ) def test_types_all() -> None: