Skip to content

Drop with boolean raises a ValueError #6189

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
jseabold opened this issue Jan 30, 2014 · 5 comments
Closed

Drop with boolean raises a ValueError #6189

jseabold opened this issue Jan 30, 2014 · 5 comments
Labels
API Design Duplicate Report Duplicate issue or pull request Enhancement Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@jseabold
Copy link
Contributor

Shouldn't this work?

>>> pd.version.version
'0.13.0-472-g9109812'

>>> df = pd.DataFrame(np.random.random((10,4)))

>>> df = df.drop(df[0] > .5)

>>> df.drop(df[0] < .2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-23-5df7f56de272> in <module>()
----> 1 df.drop(df[0] > .5)

/usr/local/lib/python2.7/dist-packages/pandas-0.13.0_472_g9109812-py2.7-linux-x86_64.egg/pandas/core/generic.pyc in drop(self, labels, axis, level, inplace, **kwargs)
   1397                 new_axis = axis.drop(labels, level=level)
   1398             else:
-> 1399                 new_axis = axis.drop(labels)
   1400             dropped = self.reindex(**{axis_name: new_axis})
   1401             try:

/usr/local/lib/python2.7/dist-packages/pandas-0.13.0_472_g9109812-py2.7-linux-x86_64.egg/pandas/core/index.pyc in drop(self, labels)
   1621         mask = indexer == -1
   1622         if mask.any():
-> 1623             raise ValueError('labels %s not contained in axis' % labels[mask])
   1624         return self.delete(indexer)
   1625 

ValueError: labels [False False  True  True  True  True  True False] not contained in axis
@jreback
Copy link
Contributor

jreback commented Jan 30, 2014

AFAICT this is not supported, labels has to be a label of the axis; I think the first one 'happens' to work. That said I don't think this is hard to fix.

@jseabold
Copy link
Contributor Author

That's what I suspected. I was wondering if boolean for drop was supported given that I couldn't for the life of me reproduce the error. Then I realized it was on the second one and it had to do with the labels being different. Consider this a feature request then. Drop is nice and expressive. Would be nice if it supported boolean indexing.

@jreback
Copy link
Contributor

jreback commented Jan 30, 2014

yep...its really just a front end to ix...so pretty easy (it just needs to NOT convert a boolean indexer from labels)

@jreback
Copy link
Contributor

jreback commented Mar 22, 2014

I believe #6599 should take care of this

@jreback jreback added this to the 0.14.0 milestone Mar 22, 2014
@jreback jreback modified the milestones: 0.14.1, 0.14.0 May 5, 2014
@jreback jreback modified the milestones: 0.15.0, 0.14.1 Jun 5, 2014
@jreback jreback modified the milestones: 0.15.0, 0.15.1 Jul 6, 2014
@jreback jreback modified the milestones: 0.16, 0.15.0 Sep 14, 2014
@jreback jreback modified the milestones: 0.16, 0.15.1 Oct 7, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Jul 11, 2017
@jreback
Copy link
Contributor

jreback commented Jul 11, 2017

closing as dupe of #16877

@jreback jreback closed this as completed Jul 11, 2017
@jorisvandenbossche jorisvandenbossche modified the milestones: No action, Next Major Release Aug 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Duplicate Report Duplicate issue or pull request Enhancement Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants