![](/img/trans.png)
[英]Why can't I read multiple HDF5 files from a folder? Meanwhile, I can read a single HDF5 file fine... (Python 3.7)
[英]Can't load HDF5 files in Python
我在讀取hdf5文件時遇到了一個奇怪的問題。 這是最新版本的Python和Numpy,以及其他軟件包。 我在Ubuntu 18.0.4上。 我可以很好地寫hdf5文件,但是當我嘗試讀取hdf5文件時,它將引發此錯誤:
ValueError Traceback (most recent call last)
<ipython-input-1-f757457e8111> in <module>
2 df = pd.DataFrame(data={'d': ['a', 'b', 'c']})
3 df.to_hdf('test.hdf', key='data')
----> 4 df = pd.read_hdf('test.hdf')
~/numpy_bug/lib/python3.7/site-packages/pandas/io/pytables.py in read_hdf(path_or_buf, key, mode, **kwargs)
392 'contains multiple datasets.')
393 key = candidate_only_group._v_pathname
--> 394 return store.select(key, auto_close=auto_close, **kwargs)
395 except:
396 # if there is an error, close the store
~/numpy_bug/lib/python3.7/site-packages/pandas/io/pytables.py in select(self, key, where, start, stop, columns, iterator, chunksize, auto_close, **kwargs)
739 chunksize=chunksize, auto_close=auto_close)
740
--> 741 return it.get_result()
742
743 def select_as_coordinates(
~/numpy_bug/lib/python3.7/site-packages/pandas/io/pytables.py in get_result(self, coordinates)
1481
1482 # directly return the result
-> 1483 results = self.func(self.start, self.stop, where)
1484 self.close()
1485 return results
~/numpy_bug/lib/python3.7/site-packages/pandas/io/pytables.py in func(_start, _stop, _where)
732 return s.read(start=_start, stop=_stop,
733 where=_where,
--> 734 columns=columns)
735
736 # create the iterator
~/numpy_bug/lib/python3.7/site-packages/pandas/io/pytables.py in read(self, start, stop, **kwargs)
2935 blk_items = self.read_index('block%d_items' % i)
2936 values = self.read_array('block%d_values' % i,
-> 2937 start=_start, stop=_stop)
2938 blk = make_block(values,
2939 placement=items.get_indexer(blk_items))
~/numpy_bug/lib/python3.7/site-packages/pandas/io/pytables.py in read_array(self, key, start, stop)
2487
2488 if isinstance(node, tables.VLArray):
-> 2489 ret = node[0][start:stop]
2490 else:
2491 dtype = getattr(attrs, 'value_type', None)
~/numpy_bug/lib/python3.7/site-packages/tables/vlarray.py in __getitem__(self, key)
679 key += self.nrows
680 (start, stop, step) = self._process_range(key, key + 1, 1)
--> 681 return self.read(start, stop, step)[0]
682 elif isinstance(key, slice):
683 start, stop, step = self._process_range(
~/numpy_bug/lib/python3.7/site-packages/tables/vlarray.py in read(self, start, stop, step)
819 listarr = []
820 else:
--> 821 listarr = self._read_array(start, stop, step)
822
823 atom = self.atom
tables/hdf5extension.pyx in tables.hdf5extension.VLArray._read_array()
ValueError: cannot set WRITEABLE flag to True of this array
這似乎是在_read_array()函數線2021 這里 。
最少的復制代碼:
import pandas as pd
df = pd.DataFrame(data={'d': ['a', 'b', 'c']})
df.to_hdf('test.hdf', key='data')
df = pd.read_hdf('test.hdf')
事實證明這是表庫中的錯誤,此錯誤已得到修復: https : //github.com/PyTables/PyTables/issues/719
使用conda conda update pytables
或pip --upgrade pytables
升級pytables庫,應該很好。
在新版本發布之前修復它的舊方法,以供參考:
一旦有新版本,就應該修復。 在此之前,您必須堅持使用numpy 1.15.4版,方法是:
pip install numpy==1.15.4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.