Implement __nonzero__ #3691

Closed
dgelvin opened this Issue May 24, 2013 · 4 comments

Comments

Projects
None yet
3 participants

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.

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
Contributor

lbeltrame commented May 24, 2013

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

Contributor

jreback commented May 24, 2013

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

jreback closed this in #3696 May 30, 2013

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