Skip to content

Providing index to pd.Series destroys categories #20009

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
andrewdalecramer opened this issue Mar 6, 2018 · 1 comment
Closed

Providing index to pd.Series destroys categories #20009

andrewdalecramer opened this issue Mar 6, 2018 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@andrewdalecramer
Copy link

Code Sample, a copy-pastable example if possible

dtype = pd.api.types.CategoricalDtype(categories=["A","B"])
ds1 = pd.Series(data="A", index=[1,2], dtype=dtype)
ds2 = pd.Series(data="A", dtype=dtype)

Problem description

In the above ds1 has lost the category "B" while ds2 has retained it.

Expected Output

Both ds1 and ds2 should have the same dtype.

Output of pd.show_versions()

pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-43-Microsoft
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 20.7.0
Cython: None
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: 2.5.0
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0b10
sqlalchemy: None
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jschendel
Copy link
Member

jschendel commented Mar 6, 2018

Looks like this was fixed on master by #19717:

In [2]: pd.__version__
Out[2]: '0.23.0.dev0+428.gaedbd94'

In [3]: dtype = pd.api.types.CategoricalDtype(categories=["A","B"])

In [4]: ds1 = pd.Series(data="A", index=[1,2], dtype=dtype)

In [5]: ds1.dtype
Out[5]: CategoricalDtype(categories=['A', 'B'], ordered=False)

In [6]: ds1
Out[6]:
1    A
2    A
dtype: category
Categories (2, object): [A, B]

@TomAugspurger TomAugspurger added this to the No action milestone Mar 6, 2018
@TomAugspurger TomAugspurger added the Duplicate Report Duplicate issue or pull request label Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants