Skip to content

Seris and DataFrame creation typing #230

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 3 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class DataFrame(NDFrame, OpsMixin):

__hash__: ClassVar[None] # type: ignore[assignment]

@overload
def __new__(
cls,
data: ListLikeU
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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 = ...,
Expand All @@ -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 = ...,
Expand All @@ -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 = ...,
Expand All @@ -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 = ...,
Expand Down
1 change: 1 addition & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_types_init() -> None:
dtype=np.int8,
copy=True,
)
pd.DataFrame(0, index=[0, 1], columns=[0, 1])
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you do check(assert_type(pd.DataFrame(0, index=[0, 1], columns=[0, 1]), pd.DataFrame), pd.DataFrame) here?

I know we don't have it above, but we're putting this in with all new tests.



def test_types_all() -> None:
Expand Down