Skip to content

CategoricalData is converted to Objects when merging dataframes #15182

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
watercrossing opened this issue Jan 20, 2017 · 3 comments
Closed

CategoricalData is converted to Objects when merging dataframes #15182

watercrossing opened this issue Jan 20, 2017 · 3 comments
Labels
Categorical Categorical Data Type Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@watercrossing
Copy link
Contributor

Code Sample

testData = pd.DataFrame(data={"id" : range(10), "cat" : pd.Categorical(["a"]*5 + ["b"]*5)})
print(testData.cat.dtype)
# category
testData2 = pd.DataFrame(data={"id" : range(10), "other" : np.random.randint(1,24,10)})
merged = pd.merge(testData, testData2,how="left", on="id")
print(merged.cat.dtype)
# object

Problem description

When merging two dataframes, an otherwise untouched categorical column is converted to an ordinary column.

Expected Output

print(merged.cat.dtype)
# category

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 742d4a5
python: 2.7.10.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.32-431.11.2.el6.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_GB.utf8
LANG: en_GB.utf8
LOCALE: None.None

pandas: 0.19.0+346.g742d4a5
nose: 1.3.7
pip: 9.0.1
setuptools: 33.1.1
Cython: 0.25.2
numpy: 1.12.0
scipy: None
statsmodels: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
pandas_datareader: None

@jreback jreback added Categorical Categorical Data Type Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jan 20, 2017
@jreback jreback added this to the No action milestone Jan 20, 2017
@jreback
Copy link
Contributor

jreback commented Jan 20, 2017

dupe of #10409

@jreback jreback closed this as completed Jan 20, 2017
@jorisvandenbossche
Copy link
Member

@watercrossing the other issue is still 'open', so it's expected this does not work yet on master

@watercrossing
Copy link
Contributor Author

@jorisvandenbossche : jreback had initially posted the wrong issue number, thats why I was confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

3 participants