Skip to content

BUG: Index doesn't have an .empty attribute #13207

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

Closed
chris-b1 opened this issue May 17, 2016 · 4 comments
Closed

BUG: Index doesn't have an .empty attribute #13207

chris-b1 opened this issue May 17, 2016 · 4 comments
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@chris-b1
Copy link
Contributor

Code Sample, a copy-pastable example if possible

In [108]: i = pd.Index([])

In [109]: bool(i)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-109-43b3c3723ad4> in <module>()
----> 1 bool(i)

C:\Users\Chris\Anaconda\envs\py35\lib\site-packages\pandas\indexes\base.py in __nonzero__(self)
   1227         raise ValueError("The truth value of a {0} is ambiguous. "
   1228                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1229                          .format(self.__class__.__name__))
   1230 
   1231     __bool__ = __nonzero__

ValueError: The truth value of a Index is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

In [110]: i.empty
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-110-1524e0ba750e> in <module>()
----> 1 i.empty

AttributeError: 'Index' object has no attribute 'empty'
@jreback
Copy link
Contributor

jreback commented May 17, 2016

yeah this could be added (or more likely the Series one moved to the Mixin)

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Difficulty Novice API Design labels May 17, 2016
@jreback jreback added this to the Next Major Release milestone May 17, 2016
@pfrcks
Copy link
Contributor

pfrcks commented May 18, 2016

@jreback I would like to work on this. Probably add an attribute to Index, perhaps in the pandas/indexes/base.py file?

@chris-b1 chris-b1 changed the title BUG? Index doesn't have an .empty attribute BUG: Index doesn't have an .empty attribute May 18, 2016
@chris-b1
Copy link
Contributor Author

@pfrcks - I think you could add it to the IndexOpsMixIn class https://github.com/pydata/pandas/blob/master/pandas/core/base.py#L794

@pfrcks
Copy link
Contributor

pfrcks commented May 18, 2016

@chris-b1 @jreback I've implemented the empty attribute and added unittests for it too. Kindly take a look.

@jreback jreback modified the milestones: 0.20.0, Next Major Release Jan 31, 2017
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 23, 2017
mattip pushed a commit to mattip/pandas that referenced this issue Apr 3, 2017
Previously, attempting to evaluate an Index in a boolean context
prints  an error message listing various alternatives, one of which is
`.empty`,  which was not actually implemented on `Index`.

Author: Scott Sanderson <[email protected]>

This patch had conflicts when merged, resolved by
Committer: Jeff Reback <[email protected]>

closes pandas-dev#13207
Closes pandas-dev#15270 from ssanderson/add-empty-to-index and squashes the following commits:

bb0126f [Scott Sanderson] ENH: Add empty property to Index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
3 participants