Skip to content

ERR: Categoricals should not allow non-strings when an object dtype is passed #13919

Closed
@hnykda

Description

@hnykda

HDF Store (with table) doesn't support categories with mixed type inside a category

Even though it is possible to store category type using to_hdf with table, you can't do that when you have mixed types inside the category. It would be nice to mention this at least on docs.

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({'a':[1, 'string']})
df['a'] = df['a'].astype('category')
df.to_hdf('play.hdf', 'main', format='table')

the error:

TypeError: Cannot serialize the column [values] because
its data contents are [mixed-integer] object dtype

Expected Output

No error, saved file.

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.6.4-1-ARCH
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.0
nose: 1.3.7
pip: 8.1.1
setuptools: 20.3
Cython: None
numpy: 1.10.4
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: 1.4.1
patsy: None
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.5.1
matplotlib: 1.5.1
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions