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

read_hdf does not close store when raise KeyError #25766

Closed
xmduhan opened this issue Mar 18, 2019 · 1 comment

Comments

@xmduhan
Copy link

commented Mar 18, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({'a': range(10), 'b': range(10)})

df.to_hdf('/tmp/1.hdf', 'k1')
try:
    pd.read_hdf('/tmp/1.hdf', 'k2')
except Exception as e:
    print(type(e))
    print(e)
    
df.to_hdf('/tmp/1.hdf', 'k2')

Problem description

<type 'exceptions.KeyError'>
'No object named k2 in the file'

The file '/tmp/1.hdf' is already opened, but in read-only mode. Please close it before reopening in append mode.

Expected Output

should not raise Exception when: df.to_hdf('/tmp/1.hdf', 'k2')

pandas/io/pytables.py line 408

 except (ValueError, TypeError):  # should also catch KeyError 

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-141-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: zh_CN.UTF-8
LOCALE: None.None

pandas: 0.24.2
pytest: 3.2.4
pip: 19.0.1
setuptools: 39.1.0
Cython: 0.27.3
numpy: 1.14.5
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 5.5.0
sphinx: 1.6.5
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.0
openpyxl: 2.4.9
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml.etree: 4.1.1
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.15
pymysql: None
psycopg2: 2.7.3.2 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@WillAyd

This comment has been minimized.

Copy link
Member

commented Mar 19, 2019

Thanks for the report! PRs are always welcome

@xmduhan xmduhan changed the title read_hdf does not close stone when raise KeyError read_hdf does not close store when raise KeyError Mar 19, 2019

@rbenes rbenes referenced this issue Mar 24, 2019
4 of 4 tasks complete

@jreback jreback added this to the 0.25.0 milestone Mar 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.