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

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

merged 5 commits into from
Aug 4, 2022

Conversation

AchmadFathoni
Copy link
Contributor

@AchmadFathoni AchmadFathoni commented Jul 19, 2022

@bashtage
Copy link
Contributor

bashtage commented Jul 19, 2022

Is that an actual supported mode for iloc? Or just an accident that works because tuples are unpacked in __s/getitem__?

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html

@AchmadFathoni
Copy link
Contributor Author

I don't know, I'm out of deep in this topic. I just following @Dr-Irv suggestion.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 19, 2022

Is that an actual supported mode for iloc? Or just an accident that works because tuples are unpacked in __s/getitem__?

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html

The example in the issue is df.iloc[0:2,]. Here the arguments to __getitem__() is tuple(slice,). Agreed it's an odd usage, but valid.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Can you also add a test in test_frame.py that fails without this change, and works with it? Copying the code from the original issue will suffice. Make sure to include a comment that refers to the issue.

@bashtage
Copy link
Contributor

The example in the issue is df.iloc[0:2,]. Here the arguments to __getitem__() is tuple(slice,). Agreed it's an odd usage, but valid.

I agree it works. I am just querying if pandas-stubs should be adding types that aren't part of the docstring. Shouldn't there be a change upstream to confirm that this is a supported format?

@AchmadFathoni AchmadFathoni requested a review from Dr-Irv August 3, 2022 14:32
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

CI failing due to black. Do poe style to make sure everything is OK.

@AchmadFathoni AchmadFathoni requested a review from Dr-Irv August 4, 2022 06:24
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

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

@Dr-Irv Dr-Irv merged commit f031ccf into pandas-dev:main Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Argument of type "tuple[slice]" cannot be assigned to parameter "idx"
3 participants