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

CategoricalIndex.reindex raises on duplicate indexer #25459

Closed
adbull opened this issue Feb 27, 2019 · 2 comments · Fixed by #28257
Closed

CategoricalIndex.reindex raises on duplicate indexer #25459

adbull opened this issue Feb 27, 2019 · 2 comments · Fixed by #28257
Labels
Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@adbull
Copy link
Contributor

adbull commented Feb 27, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd

# works fine
x = pd.Series([0])
x.reindex([0,0])

# ValueError: cannot reindex with a non-unique indexer
x.index = x.index.astype('category')
x.reindex([0,0])

Problem description

When a series or frame has a categorical index, it cannot be reindexed using an indexer that has duplicate values. This is inconsistent with other indexes, and makes categorical indexes less useful.

Expected Output

No error.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Linux
OS-release: 4.19.15-200.fc28.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.24.1
pytest: 4.3.0
pip: 19.0.3
setuptools: 40.8.0
Cython: 0.29.5
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 4.2.1
sphinx: None
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: 1.2.1
tables: None
numexpr: 2.6.2
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.3.1
bs4: 4.7.1
html5lib: None
sqlalchemy: 1.2.18
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@gfyoung gfyoung added Indexing Related to indexing on series/frames, not to indexes themselves Categorical Categorical Data Type labels Mar 1, 2019
@gfyoung
Copy link
Member

gfyoung commented Mar 1, 2019

cc @jreback @toobaz

@batterseapower
Copy link
Contributor

batterseapower commented Aug 22, 2019

This was broken by #23963 which was trying to fix #21809. The problem is that this line should be checking self.is_unique instead of target.is_unique:

if not target.is_unique:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type 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