Skip to content

Add Tuple[slice] in iLocIndexerFrame. Fix #143 #152

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 5 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ class _iLocIndexerFrame(_iLocIndexer):
@overload
def __getitem__(
self,
idx: IndexType | MaskType | tuple[IndexType | MaskType, IndexType | MaskType] | tuple[slice],
idx: IndexType
| MaskType
| tuple[IndexType | MaskType, IndexType | MaskType]
| tuple[slice],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry - I should have picked up on this before. Use

tuple[IndexType | MaskType, IndexType | MaskType | slice]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That change fails the test I made

Type "tuple[slice]" cannot be assigned to type "IndexType | MaskType | tuple[IndexType | MaskType, IndexType | MaskType]"

Copy link
Collaborator

Choose a reason for hiding this comment

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

My mistake. I missed the comma

) -> DataFrame: ...
def __setitem__(
self,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,9 @@ def test_iloc_npint() -> None:
# https://github.com/pandas-dev/pandas-stubs/issues/143
def test_iloc_tuple() -> None:
df = pd.DataFrame({"Char": ["A", "B", "C"], "Number": [1, 2, 3]})
df = df.iloc[0:2,]
df = df.iloc[
0:2,
]


def test_set_columns() -> None:
Expand Down