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

PerformanceWarning: misleading warning for all columns #28460

Open
jankislinger opened this issue Sep 16, 2019 · 1 comment
Open

PerformanceWarning: misleading warning for all columns #28460

jankislinger opened this issue Sep 16, 2019 · 1 comment
Labels
Bug IO HDF5 read_hdf, HDFStore Strings String extension data type and string data Warnings Warnings that appear or should be added to pandas

Comments

@jankislinger
Copy link

Code Sample

import pandas as pd

df = pd.DataFrame({'string': ['a', 'b'], 'number': [1.0, 2.0], 'mix': ['a', 2.0]})
df.to_hdf('foo.h5', 'data')

Problem description

The problem is related to the feature added in #3622. The warning for types that cannot be saved as c-types applies for all object columns if any such column exists in the data frame. If all columns are either strings or numbers (but not mixed within a column) no warning is produced (which is expected).

Output

python3.6/site-packages/pandas/core/generic.py:2530: PerformanceWarning: 
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->mixed,key->block1_values] [items->['string', 'mix']]

  pytables.to_hdf(path_or_buf, key, self, **kwargs)

Expected Output

Warnings only for column mix.

INSTALLED VERSIONS

commit : None
python : 3.6.8.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-58-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.1
numpy : 1.17.1
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.2.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 : 2.7.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : 3.5.2
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@TomAugspurger
Copy link
Contributor

This seems somewhat difficult to fix, since the caller is the one passing items which is passed to the error message, but we don't know the actual types of string vs. mixed till where we raise the warning.

The line

inferred_type = lib.infer_dtype(value.ravel(), skipna=False)

Can be applied to each column in value, and the subset of items that are mixed included in the error message.

Note that this will be mostly obsolete once we have a proper String dtype (#8640).

@TomAugspurger TomAugspurger added IO HDF5 read_hdf, HDFStore Strings String extension data type and string data Error Reporting Incorrect or improved errors from pandas labels Sep 16, 2019
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Sep 16, 2019
@mroeschke mroeschke added Bug Warnings Warnings that appear or should be added to pandas and removed Error Reporting Incorrect or improved errors from pandas labels May 3, 2020
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HDF5 read_hdf, HDFStore Strings String extension data type and string data Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

No branches or pull requests

3 participants