DaanVanVugt / h5pickle

Wrapper for h5py with pickle capabilities
MIT License
25 stars 8 forks source link

Error when opening closed file again #14

Open fzalkow opened 1 year ago

fzalkow commented 1 year ago

Hi, and many thanks for h5pickle! I encountered an issue when closing a file, re-opening it, and reading from it again.

Short example:

import h5pickle

h5file = h5pickle.File(filename_hdf5_archive, 'r')  # open file
h5file[dataset_path][...]                           # reading works fine
h5file.close()                                      # close file

h5file = h5pickle.File(filename_hdf5_archive, 'r')  # re-open file
h5file[dataset_path][...]                           # reading again throws an error

The error message is:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "PYTHONPATH/site-packages/h5pickle/__init__.py", line 132, in __getitem__
    obj = h5py_wrap_type(h5py.Group.__getitem__(self, name))
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "PYTHONPATH/site-packages/h5py/_hl/group.py", line 357, in __getitem__
    oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5o.pyx", line 190, in h5py.h5o.open
ValueError: Invalid location identifier (invalid location identifier)

Using plain h5py, the code works without errors. I use h5py 3.8.0 and h5pickle 0.4.2 with python 3.7.16.

DaanVanVugt commented 1 year ago

Hi Frank, I am not sure if this is a new problem or not. Could you try running the unit tests against this version of h5py?

fzalkow commented 1 year ago

The unit tests seem to work fine.

$ git clone git@github.com:DaanVanVugt/h5pickle.git
Cloning into 'h5pickle'...
remote: Enumerating objects: 67, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 67 (delta 0), reused 1 (delta 0), pack-reused 63
Receiving objects: 100% (67/67), 13.43 KiB | 2.24 MiB/s, done.
Resolving deltas: 100% (30/30), done.
$ cd h5pickle
$ pytest tests
============================= test session starts ==============================
platform linux -- Python 3.7.16, pytest-7.2.2, pluggy-1.0.0
rootdir: /user_directory/h5pickle
plugins: typeguard-3.0.2, torchtyping-0.1.4, anyio-3.6.2
collected 9 items

tests/test_pickling_dataset.py .                                         [ 11%]
tests/test_pickling_protocols.py xx..                                    [ 55%]
tests/test_pickling_single_process.py ...                                [ 88%]
tests/test_repickling.py .                                               [100%]

========================= 7 passed, 2 xfailed in 0.08s =========================