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

Categorical.from_codes fails for the (new nullable) Int64 dtype #31779

Closed
mila opened this issue Feb 7, 2020 · 1 comment · Fixed by #31794
Closed

Categorical.from_codes fails for the (new nullable) Int64 dtype #31779

mila opened this issue Feb 7, 2020 · 1 comment · Fixed by #31794
Labels
Bug Categorical Categorical Data Type Constructors Series/DataFrame/Index/pd.array Constructors
Milestone

Comments

@mila
Copy link

mila commented Feb 7, 2020

Code Sample, a copy-pastable example if possible

>>> import pandas as pd
>>> codes = pd.Series([1, 0], dtype="Int64")
>>> pd.Categorical.from_codes(codes, categories=["foo", "bar"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python3.7/site-packages/pandas/core/arrays/categorical.py", line 649, in from_codes
    raise ValueError("codes need to be array-like integers")
ValueError: codes need to be array-like integers

Problem description

Categories.from_codes works with Series with the Numpy "int64" dtype.

>>> codes = pd.Series([1, 0])
>>> pd.Categorical.from_codes(codes, categories=["foo", "bar"])
[bar, foo]
Categories (2, object): [foo, bar]

I would expect that it will work with the new Pandas "Int64" dtype.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@jreback jreback added the Bug label Feb 12, 2020
@jreback jreback added this to the 1.0.2 milestone Feb 12, 2020
@jreback jreback added Categorical Categorical Data Type Constructors Series/DataFrame/Index/pd.array Constructors labels Feb 12, 2020
@mila
Copy link
Author

mila commented Feb 12, 2020

Thanks, that was fast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type Constructors Series/DataFrame/Index/pd.array Constructors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants