Skip to content

DOC: tail works even if n > length of DataFrame #46079

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
kevinlinxc opened this issue Feb 19, 2022 · 6 comments · Fixed by #46466
Closed
1 task done

DOC: tail works even if n > length of DataFrame #46079

kevinlinxc opened this issue Feb 19, 2022 · 6 comments · Fixed by #46466

Comments

@kevinlinxc
Copy link

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.tail.html

Documentation problem

It may be obvious to some, but if the n requested by tail() is greater than the length of the DataFrame, you get the entire DataFrame and no errors are thrown, and this is not mentioned in the documentation. This is useful for me because I'm trying to plot only the last 70 data points of a dataframe but the dataframe might not have 70 values yet. I think it would be reasonable to assume that one implementation would throw an out-of-bounds style exception.

Suggested fix for documentation

Add one line about how n > dataframe length is handled.

@kevinlinxc kevinlinxc added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 19, 2022
@attack68
Copy link
Contributor

I strongly disagree on exception. This follows python's core logic:

>>> a = [0, 1]
>>> a[:5]
[0, 1]

Doc edits generally welcome if they make things more explicit.

@jreback
Copy link
Contributor

jreback commented Feb 20, 2022

yep no exception is warranted

@somieee20
Copy link

Working fine

@kevinlinxc
Copy link
Author

kevinlinxc commented Feb 22, 2022

I think you have misunderstood. I am not calling for an exception to be raised, I am asking that the documentation state that no exception is raised and state what the behaviour actually is (returning the entire df). I was stating that someone reading the documentation right now has no clue what the edge case behaviour is, and some clarification would be a value add to the documentation.

@MarcoGorelli MarcoGorelli added good first issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 22, 2022
@arneja-arnav
Copy link

Hi. I would like to get on this issue. Could it be assigned to me?

@arneja-arnav
Copy link

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants