Skip to content

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

Merged
merged 1 commit into from
Jan 15, 2014
Merged

BUG: tail raises on empty DataFrame #5848

merged 1 commit into from
Jan 15, 2014

Conversation

MichaelWS
Copy link
Contributor

closes #5846

calling tail on an empty frame threw an exception. In addition, df.tail(0) returns self without indexing.

@jreback
Copy link
Contributor

jreback commented Jan 4, 2014

had and tail should have very similar checking code for the edge cases

@MichaelWS
Copy link
Contributor Author

added a check for empty frame for head as well.

@jreback
Copy link
Contributor

jreback commented Jan 4, 2014

@MichaelWS fyi....I edited the title / top of the PR.

putting the closes issue number sets up a link the original issue, then automatically closes it when its merged.

@MichaelWS
Copy link
Contributor Author

Thanks.

n = l if n > 0 else -l
if l == 0 or n == 0:
return self
if n > l:
Copy link
Contributor

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?

Copy link
Contributor Author

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)

@jreback
Copy link
Contributor

jreback commented Jan 5, 2014

don't change the test

can u show me what is returned kn both current and your case for head(0)?

@MichaelWS
Copy link
Contributor Author

Currently it returns:
In [3]: pd.DataFrame([1,2,3]).head(0)
Out[3]:
Empty DataFrame
Columns: [0]
Index: []

[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.

@MichaelWS
Copy link
Contributor Author

My case would be:

In [3]: pd.DataFrame([1,2,3]).head(0)
Out[3]:
0
0 1
1 2
2 3

[3 rows x 1 columns]

@jreback
Copy link
Contributor

jreback commented Jan 5, 2014

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?

@MichaelWS
Copy link
Contributor Author

yes, please make an issue on that.
I agree with you. I think self makes more sense.

@jreback
Copy link
Contributor

jreback commented Jan 14, 2014

can you rebase this?

@MichaelWS
Copy link
Contributor Author

sure. this is done.

@MichaelWS
Copy link
Contributor Author

The only real functionality change is df.head(0) returns self

@jreback
Copy link
Contributor

jreback commented Jan 14, 2014

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)

@MichaelWS
Copy link
Contributor Author

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`)
Copy link
Contributor

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)

@jreback jreback merged commit 66b9e8c into pandas-dev:master Jan 15, 2014
@jreback
Copy link
Contributor

jreback commented Jan 15, 2014

thanks for the PR!

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

Successfully merging this pull request may close these issues.

tail throws exception on empty frame
2 participants