Skip to content
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

Implement __nonzero__ #3691

Closed
dgelvin opened this issue May 24, 2013 · 4 comments · Fixed by #3696
Closed

Implement __nonzero__ #3691

dgelvin opened this issue May 24, 2013 · 4 comments · Fixed by #3696

Comments

@dgelvin
Copy link

dgelvin commented May 24, 2013

It would be nice if dataframe instances implemented __nonzero__ so you could test if a dataframe is empty or not as if it were a boolean.

@jreback
Copy link
Contributor

jreback commented May 24, 2013

This is pretty easy, but trying to rememeber if we there was a reason for not supporting this....

If you would like to do a PR (and see if anything else breaks)

(and prob should do this for Series and for NDFrame)

In [9]: def nonzero(frame):
   ...:     return len(frame) != 0
   ...: 

In [10]: DataFrame.__nonzero__ = DataFrame.__bool__ = nonzero

In [11]: print 'non-empty' if df else 'empty'
empty

@lbeltrame
Copy link
Contributor

Isn't there a DataFrame.empty property which does exactly this?

@jreback
Copy link
Contributor

jreback commented May 24, 2013

@cswegger yep there is, but this is actually a aslight API change

@jreback
Copy link
Contributor

jreback commented May 30, 2013

closed by #3696

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

Successfully merging a pull request may close this issue.

3 participants