Skip to content

Commit

Permalink
Fixing lazy loading for pynajax
Browse files Browse the repository at this point in the history
  • Loading branch information
gviejo committed May 28, 2024
1 parent 1f4a8c3 commit d28cc62
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tests/test_lazy_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_lazy_load_hdf5_is_array(time, data, convert_flag):
h5_data = h5py.File(file_path, 'r')["data"]
tsd = nap.Tsd(t=time, d=h5_data, load_array=convert_flag)
if convert_flag:
assert isinstance(tsd.d, np.ndarray)
assert not isinstance(tsd.d, h5py.Dataset)
else:
assert isinstance(tsd.d, h5py.Dataset)
finally:
Expand All @@ -77,7 +77,7 @@ def test_lazy_load_hdf5_apply_func(time, data, func,cls):
# lazy load and apply function
res = func(cls(t=time, d=h5_data, load_array=False))
assert isinstance(res, cls)
assert isinstance(res.d, np.ndarray)
assert not isinstance(res.d, h5py.Dataset)
finally:
# delete file
if file_path.exists():
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_lazy_load_hdf5_apply_method(time, data, method_name, args, cls):
tsd = cls(t=time, d=h5_data, load_array=False)
func = getattr(tsd, method_name)
out = func(*args)
assert isinstance(out.d, np.ndarray)
assert not isinstance(out.d, h5py.Dataset)
finally:
# delete file
if file_path.exists():
Expand Down Expand Up @@ -192,20 +192,23 @@ def test_lazy_load_hdf5_tsdframe_loc():
file_path.unlink()

@pytest.mark.parametrize(
"lazy, expected_type",
"lazy",
[
(True, h5py.Dataset),
(False, np.ndarray),
(True),
(False),
]
)
def test_lazy_load_nwb(lazy, expected_type):
def test_lazy_load_nwb(lazy):
try:
nwb = nap.NWBFile("tests/nwbfilestest/basic/pynapplenwb/A2929-200711.nwb", lazy_loading=lazy)
except:
nwb = nap.NWBFile("nwbfilestest/basic/pynapplenwb/A2929-200711.nwb", lazy_loading=lazy)

tsd = nwb["z"]
assert isinstance(tsd.d, expected_type)
if lazy:
assert isinstance(tsd.d, h5py.Dataset)
else:
assert not isinstance(tsd.d, h5py.Dataset)
nwb.io.close()


Expand Down

0 comments on commit d28cc62

Please sign in to comment.