-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
BUG: tail raises on empty DataFrame #5848
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
Conversation
had and tail should have very similar checking code for the edge cases |
added a check for empty frame for head as well. |
@MichaelWS fyi....I edited the title / top of the PR. putting the |
Thanks. |
n = l if n > 0 else -l | ||
if l == 0 or n == 0: | ||
return self | ||
if n > l: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need similar logic on head, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added similar logic on head now. The question is this changes how df.head(0) works. It now returns self. before it returned the same as df.head(1)
don't change the test can u show me what is returned kn both current and your case for head(0)? |
Currently it returns: [0 rows x 1 columns] I could easily keep that functionality. I am not sure why someone would call df.head(0) for a non-empty frame. |
My case would be: In [3]: pd.DataFrame([1,2,3]).head(0) [3 rows x 1 columns] |
yours is my right bug neither is the original I think it should return self iloc[0] on an empty frame is wrong too I think - can I make an issue for that one? |
yes, please make an issue on that. |
can you rebase this? |
sure. this is done. |
The only real functionality change is df.head(0) returns self |
hmm...ok why don't you put an additional note in the API section (leave your existing one their). I don't think its a big deal but should document it (reference this issue or original again) |
I put a note in the docs. |
@@ -90,6 +90,8 @@ Bug Fixes | |||
- Bug in ``BusinessDay`` when adding n days to a date not on offset when n>5 and n%5==0 (:issue:`5890`) | |||
- Bug in assigning to chained series with a series via ix (:issue:`5928`) | |||
- Bug in creating an empty DataFrame, copying, then assigning (:issue:`5932`) | |||
- Bug in DataFrame.tail with empty frame (:issue:`5846`) | |||
- DataFrame.head(0) returns self instead of empty frame (:issue:`5846`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put this in the API section (the last one)
thanks for the PR! |
closes #5846
calling tail on an empty frame threw an exception. In addition, df.tail(0) returns self without indexing.