Skip to content

HDF Store with multi-index problems when using data_columns=True #14435

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
MMCMA opened this issue Oct 16, 2016 · 1 comment
Closed

HDF Store with multi-index problems when using data_columns=True #14435

MMCMA opened this issue Oct 16, 2016 · 1 comment
Labels
Milestone

Comments

@MMCMA
Copy link

MMCMA commented Oct 16, 2016

Not sure if this is supposed to be like this. When I store a multi-index along with the option data_column=True, I cannot query along the dataframe indexes only the columns are valid references. However, it works when I store them with the option data_columns=[...].

import pandas as pd
import numpy as np

#adjust the path
file_path = 'D:\\test_store.h5'
np.random.seed(1234)
pd.set_option('display.max_rows',4)
# simulate some data
index = pd.MultiIndex.from_product([np.arange(10000,10200),
                                    pd.date_range('19800101',periods=500)],
                                   names=['id','date'])
df = pd.DataFrame(dict(id2=np.random.randint(0, 1000, size=len(index)),
                       w=np.random.randn(len(index))),
                  index=index).reset_index().set_index(['id', 'date'])

# store the data
store =  pd.HDFStore(file_path,mode='a',complib='blosc', complevel=9)
store.append('df_dc_None', df, data_columns=None)
store.append('df_dc_explicit', df, data_columns=['id2', 'w'])
store.append('df_dc_True', df, data_columns=True)
store.close()

# query the data
start = '19810201'
print(pd.read_hdf(file_path,'df_dc_None', where='date>start & id=10000'))
print(pd.read_hdf(file_path,'df_dc_True', where='id2>500'))
print(pd.read_hdf(file_path,'df_dc_explicit', where='date>start & id2>500'))
try:
    print(pd.read_hdf(file_path,'df_dc_True', where='date>start & id2>500'))
except ValueError as err:
    print(err)

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.19.0
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.2
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.3.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: 0.7.9.None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: 0.2.1

@chris-b1
Copy link
Contributor

Thanks for the example, yes, I think this should work - PR welcome if you're interested.

@chris-b1 chris-b1 added Bug IO HDF5 read_hdf, HDFStore MultiIndex labels Oct 16, 2016
@chris-b1 chris-b1 added this to the Next Major Release milestone Oct 16, 2016
@chris-b1 chris-b1 modified the milestones: 0.19.2, Next Major Release Dec 3, 2016
@jreback jreback closed this as completed in 27fcd81 Dec 4, 2016
jorisvandenbossche pushed a commit that referenced this issue Dec 15, 2016
closes #14435

Author: Chris <[email protected]>

Closes #14791 from chris-b1/hdf-mi-datacolumns and squashes the following commits:

5d32610 [Chris] BUG: multi-index HDFStore data_columns=True

(cherry picked from commit 27fcd81)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants