-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
head(0) and tail(0) return empty DataFrames #11937
Conversation
return self | ||
if n == 0: | ||
return self.iloc[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.
I think self.iloc[0:0]
is clearer here. I don't think you need l
anymore (was it ever needed?).
The side question here is: should we check that n>0? I don't think we need to... as this will make it kinda useful: it'll return the rest of the dataframe except the head(n) == tail(len(df) - n).
Edit: or n>=0.
make sure to test groupby! (need updating maybe) |
Fixing the broken unit test.... |
@@ -2146,8 +2147,10 @@ def tail(self, n=5): | |||
Returns last n rows | |||
""" | |||
l = len(self) | |||
if l == 0 or n == 0: | |||
if l == 0: |
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.
This l is not required. self.iloc[-0:] == self
:)
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.
So why was it there in the first place? I don't really understand what its doing in either head() or tail().
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 think it was due to the n == 0 or n == l
check that was there before. Even in that case there's no need to avoid the iloc
in the latter case; code is simpler without it.
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.
Ok, I've taken the checks out.
groupby is already tested: https://github.com/pydata/pandas/blob/a89f48940cd0a7346302311011beb3a09e9be292/pandas/tests/test_groupby.py#L1912-L1913. thanks! lgtm, but please squash. |
I don't really understand why Travis is failing - it seems to be some kind of connection error? Is that something I've done wrong? |
Looks unrelated. squash and maybe the tests will pass next time :) |
I'm sorry, I'm not sure what you mean by 'squash'. |
Ah, ok. I think I did that right, hopefully the tests will pass this time. |
Need more thing, a release note in |
Added a note in the release docs. |
@@ -166,6 +166,7 @@ Backwards incompatible API changes | |||
|
|||
- The parameter ``out`` has been removed from the ``Series.round()`` method. (:issue:`11763`) | |||
- ``DataFrame.round()`` leaves non-numeric columns unchanged in its return, rather than raises. (:issue:`11885`) | |||
- ``DataFrame.head(0)`` and ``DataFrame.tail(0)`` return empty frames, rather than ``self``. (:issue:`11937`) |
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.
Mention Series as well here
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.
done
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.
actually Series was already doing this. But that's fine.
unit test for Series.head(0), Series.tail(0) fixed breaking unit tests on Series.head(0)/Series.tail(0) removed unnecessary length checks added documentation mention series in API docs
ok, lgtm. ping when green. |
head(0) and tail(0) return empty DataFrames
Great! |
closes #11930
frame.head(0) and frame.tail(0) now return empty DataFrames.