ERR: disallow read_hdf mode='w' · Issue #13623 · pandas-dev/pandas (original) (raw)
Passing mode='w'
to pd.read_hdf
erases the target file immediately.
I believe this behavior is undesired, because deleting data is a side effect that no method called read_anything
should have. The fact that a mode argument is even accepted is not documented anywhere. I just lost some experimental data this way, no backup...
Code Sample
import pandas as pd import numpy as np df = pd.DataFrame(data=np.random.rand(10))
#write some data to a new hdf5 file df.to_hdf('test.hdf','test')
#read back the data with mode='w' df = pd.read_hdf('test.hdf','test',mode='w')
Expected Output
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-4-5659d158fdb7> in <module>()
----> 1 df = pd.read_hdf('test.hdf','test',mode='w')
C:\Anaconda2\lib\site-packages\pandas\io\pytables.pyc in read_hdf(path_or_buf, key, **kwargs)
328 'multiple datasets.')
329 key = keys[0]
--> 330 return store.select(key, auto_close=auto_close, **kwargs)
331 except:
332 # if there is an error, close the store
C:\Anaconda2\lib\site-packages\pandas\io\pytables.pyc in select(self, key, where, start, stop, columns, iterator, chunksize, auto_close, **kwargs)
660 group = self.get_node(key)
661 if group is None:
--> 662 raise KeyError('No object named %s in the file' % key)
663
664 # create the storer and axes
KeyError: 'No object named test in the file'
output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.11.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
pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: 1.0.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: None
psycopg2: None
jinja2: 2.8
boto: 2.40.0
pandas_datareader: None