Skip to content

DOC: iloc docs should indicate a tuple is valid #47799

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

Closed
1 task done
Dr-Irv opened this issue Jul 20, 2022 · 3 comments · Fixed by #47989
Closed
1 task done

DOC: iloc docs should indicate a tuple is valid #47799

Dr-Irv opened this issue Jul 20, 2022 · 3 comments · Fixed by #47989
Labels
Docs good first issue Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Jul 20, 2022

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

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

Documentation problem

In the docs, we say these are valid parameters:

  • An integer, e.g. 5.
  • A list or array of integers, e.g. [4, 3, 0].
  • A slice object with ints, e.g. 1:7.
  • A boolean array.
  • A callable function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above). This is useful in method chains, when you don’t have a reference to the calling object, but would like to base your selection on some value.

But a 2D tuple is valid as well, as shown in the example at the bottom of the page. So this should be indicated in the docs.

Also, a 1D tuple like df.iloc[0:2,] works as well.

See discussion in pandas-stubs at pandas-dev/pandas-stubs#152

Suggested fix for documentation

Add tuple description to list at the top.

@Dr-Irv Dr-Irv added Docs Needs Triage Issue that has not been reviewed by a pandas team member Indexing Related to indexing on series/frames, not to indexes themselves good first issue labels Jul 20, 2022
@roy840831
Copy link

Hi, I would to like work on this issue.

@berstearns
Copy link

Hi,

Could you give an example what would be a 2D-tuple call in this context ? You meant there's an example on the bottom of the page, but I could not find it.

Thanks

@Dr-Irv
Copy link
Contributor Author

Dr-Irv commented Jul 21, 2022

df.iloc[1:3, 0:3]

In python, that gets translated to df.iloc.__getitem__(tuple(slice(1,3), slice(0,3)))

You can also do things like df.iloc[0:1,1]

@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Jul 22, 2022
pratikpatel2512 added a commit to pratikpatel2512/pandas that referenced this issue Aug 6, 2022
mroeschke pushed a commit that referenced this issue Aug 8, 2022
DOC: Add tuple description to allowed inputs for iloc
noatamir pushed a commit to noatamir/pandas that referenced this issue Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs good first issue Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants