Skip to content

Error with .drop([]) on non-unique index #16398

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
toobaz opened this issue May 20, 2017 · 1 comment · Fixed by #16428
Closed

Error with .drop([]) on non-unique index #16398

toobaz opened this issue May 20, 2017 · 1 comment · Fixed by #16428
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@toobaz
Copy link
Member

toobaz commented May 20, 2017

Code Sample, a copy-pastable example if possible

In [2]: pd.DataFrame([[1,2], [3,4], [5,6]], index=['a','a','b']).drop(['a'])
Out[2]: 
   0  1
b  5  6

In [3]: pd.DataFrame([[1,2], [3,4], [5,6]], index=['a','a','b']).drop(['b'])
Out[3]: 
   0  1
a  1  2
a  3  4

In [4]: pd.DataFrame([[1,2], [3,4], [5,6]], index=['a','a','b']).drop([])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-ae217de2434b> in <module>()
----> 1 pd.DataFrame([[1,2], [3,4], [5,6]], index=['a','a','b']).drop([])

/home/pietro/.local/lib/python3.5/site-packages/pandas/core/generic.py in drop(self, labels, axis, level, inplace, errors)
   2063                 indexer = ~axis.get_level_values(level).isin(labels)
   2064             else:
-> 2065                 indexer = ~axis.isin(labels)
   2066 
   2067             slicer = [slice(None)] * self.ndim

/home/pietro/.local/lib/python3.5/site-packages/pandas/core/indexes/base.py in isin(self, values, level)
   2766         if level is not None:
   2767             self._validate_index_level(level)
-> 2768         return algos.isin(np.array(self), values)
   2769 
   2770     def _can_reindex(self, indexer):

/home/pietro/.local/lib/python3.5/site-packages/pandas/core/algorithms.py in isin(comps, values)
    419             comps = comps.astype(object)
    420 
--> 421     return f(comps, values)
    422 
    423 

/home/pietro/.local/lib/python3.5/site-packages/pandas/core/algorithms.py in <lambda>(x, y)
    397     # work-around for numpy < 1.8 and comparisions on py3
    398     # faster for larger cases to use np.in1d
--> 399     f = lambda x, y: htable.ismember_object(x, values)
    400     if (_np_version_under1p8 and compat.PY3) or len(comps) > 1000000:
    401         f = lambda x, y: np.in1d(x, y)

/home/pietro/nobackup/repo/pandas/pandas/_libs/hashtable_func_helper.pxi in pandas._libs.hashtable.ismember_object (pandas/_libs/hashtable.c:29677)()

ValueError: Buffer dtype mismatch, expected 'Python object' but got 'double'

Problem description

Notice pd.DataFrame([[1,2], [3,4], [5,6]], index=['a','b', 'c']).drop([]) works just fine.

Expected Output

Just the original DataFrame.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.7.0-1-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: it_IT.utf8
LOCALE: it_IT.UTF-8

pandas: 0.20.1
pytest: 3.0.6
pip: 9.0.1
setuptools: None
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: 0.9.2
IPython: 5.1.0.dev
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.3.0
numexpr: 2.6.1
feather: 0.3.1
matplotlib: 2.0.2
openpyxl: 2.3.0
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.6
lxml: 3.7.1
bs4: 4.5.3
html5lib: 0.999999999
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: 0.2.1

@TomAugspurger TomAugspurger added Bug Difficulty Intermediate Indexing Related to indexing on series/frames, not to indexes themselves labels May 20, 2017
@TomAugspurger TomAugspurger added this to the Next Major Release milestone May 20, 2017
@lkirk
Copy link
Contributor

lkirk commented May 22, 2017

Working on this as a part of the pycon sprint

@jreback jreback modified the milestones: 0.20.2, Next Major Release May 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants