head(0) and tail(0) return empty DataFrames by trvrm · Pull Request #11937 · pandas-dev/pandas (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation21 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

trvrm

closes #11930

frame.head(0) and frame.tail(0) now return empty DataFrames.

@trvrm trvrm mentioned this pull request

Dec 31, 2015

hayd

return self
if n == 0:
return self.iloc[l:]

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.

@jreback

make sure to test groupby! (need updating maybe)

@trvrm

Fixing the broken unit test....

hayd

@@ -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:

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 :)

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().

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.

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.

@hayd

@trvrm

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?

@hayd

Looks unrelated. squash and maybe the tests will pass next time :)

@trvrm

I'm sorry, I'm not sure what you mean by 'squash'.

@jreback

@trvrm

Ah, ok. I think I did that right, hopefully the tests will pass this time.

@TomAugspurger

Need more thing, a release note in doc/source/whatsnew/v0.18.0, maybe under the API changes section, to document the change. You can squash that commit as well (which you did correctly). Thanks!

@trvrm

Added a note in the release docs.

jreback

@@ -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`)

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

Choose a reason for hiding this comment

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

done

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

@jreback

ok, lgtm. ping when green.

hayd added a commit that referenced this pull request

Jan 2, 2016

@hayd

head(0) and tail(0) return empty DataFrames

@hayd