Reputation: 772
I am new to HDF5 and I am trying to figure out how to open and overwrite an HDF5 file that has a user block in python 2.7 and using h5py version 2.1.3.
Lets say I create a file in the following way:
import numpy as np
import h5py
def newfile(filename):
'''This is a test function for creating an HDF5 file.'''
# create dummy data for now
data = np.zeros(100)
# create the file and stick data in a dataset in the root group
with h5py.File(filename, mode="w", userblock_size=512) as f:
f['dataset'] = data
# populate the user block with something after file has been closed
with open(filename, "rb+") as f:
f.write('This is a test of the user block, just a place to put ' +
'random data')
When this file does not exist, this function creates a new file as expected with data and the user block is populated. However, if I try to run the same function after the file is already created (ie. running it twice without removing the file) I receive:
IOError: unable to create file (File accessibilty: Unable to open file)
This was surprising to me. I expected that this file would be overwritten because I initially opened the file with mode="w" which is supposed to overwrite.
But, if I remove the user block creation from the original file creation the file is successfully overwritten as expected. Did I do something wrong in creating the user block data or did I stumble onto an issue with HDF5 and user blocks that I am not correctly handling?
Upvotes: 0
Views: 539
Reputation: 772
This appears to be a bug in the way the old versions of hdf5 (version 1.8.11) and h5py (version 2.1.3) interact. The solution is to upgrade to the current version of both which are HDF5 1.8.15 and h5py 2.5.0. This effectively solves the problem in python 2.7.5.
Upvotes: 0