Skip to content

Commit

Permalink
renamed flag
Browse files Browse the repository at this point in the history
  • Loading branch information
BalzaniEdoardo committed May 21, 2024
1 parent 183a951 commit 57b9a1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions pynapple/core/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class BaseTsd(Base, NDArrayOperatorsMixin, abc.ABC):
Implement most of the shared functions across concrete classes `Tsd`, `TsdFrame`, `TsdTensor`
"""

def __init__(self, t, d, time_units="s", time_support=None, to_numpy_array=True):
def __init__(self, t, d, time_units="s", time_support=None, load_array=True):
super().__init__(t, time_units, time_support)

if to_numpy_array:
if load_array:
self.values = convert_to_array(d, "d")
else:
if not is_array_like(d):
Expand Down Expand Up @@ -673,7 +673,7 @@ class TsdTensor(BaseTsd):
"""

def __init__(
self, t, d, time_units="s", time_support=None, to_numpy_array=True, **kwargs
self, t, d, time_units="s", time_support=None, load_array=True, **kwargs
):
"""
TsdTensor initializer
Expand All @@ -689,7 +689,7 @@ def __init__(
time_support : IntervalSet, optional
The time support of the TsdFrame object
"""
super().__init__(t, d, time_units, time_support, to_numpy_array)
super().__init__(t, d, time_units, time_support, load_array)

assert (
self.values.ndim >= 3
Expand Down Expand Up @@ -850,7 +850,7 @@ def __init__(
time_units="s",
time_support=None,
columns=None,
to_numpy_array=True,
load_array=True,
):
"""
TsdFrame initializer
Expand Down Expand Up @@ -879,7 +879,7 @@ def __init__(
else:
assert d is not None, "Missing argument d when initializing TsdFrame"

super().__init__(t, d, time_units, time_support, to_numpy_array)
super().__init__(t, d, time_units, time_support, load_array)

assert self.values.ndim <= 2, "Data should be 1 or 2 dimensional."

Expand Down Expand Up @@ -1129,7 +1129,7 @@ class Tsd(BaseTsd):
"""

def __init__(
self, t, d=None, time_units="s", time_support=None, to_numpy_array=True, **kwargs
self, t, d=None, time_units="s", time_support=None, load_array=True, **kwargs
):
"""
Tsd Initializer.
Expand All @@ -1151,7 +1151,7 @@ def __init__(
else:
assert d is not None, "Missing argument d when initializing Tsd"

super().__init__(t, d, time_units, time_support, to_numpy_array)
super().__init__(t, d, time_units, time_support, load_array)

assert self.values.ndim == 1, "Data should be 1 dimensional"

Expand Down
6 changes: 3 additions & 3 deletions pynapple/io/interface_nwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _make_tsd(obj):
else:
t = obj.starting_time + np.arange(obj.num_samples) / obj.rate

data = nap.Tsd(t=t, d=d, to_numpy_array=False)
data = nap.Tsd(t=t, d=d, load_array=False)

return data

Expand All @@ -173,7 +173,7 @@ def _make_tsd_tensor(obj):
else:
t = obj.starting_time + np.arange(obj.num_samples) / obj.rate

data = nap.TsdTensor(t=t, d=d, to_numpy_array=False)
data = nap.TsdTensor(t=t, d=d, load_array=False)

return data

Expand Down Expand Up @@ -232,7 +232,7 @@ def _make_tsd_frame(obj):
else:
columns = np.arange(obj.data.shape[1])

data = nap.TsdFrame(t=t, d=d, columns=columns, to_numpy_array=False)
data = nap.TsdFrame(t=t, d=d, columns=columns, load_array=False)

return data

Expand Down
14 changes: 7 additions & 7 deletions tests/test_lazy_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_lazy_load_hdf5_is_array(time, data, expectation):
f.create_dataset('data', data=data)
h5_data = h5py.File(file_path, 'r')["data"]
with expectation:
nap.Tsd(t=time, d=h5_data, to_numpy_array=False)
nap.Tsd(t=time, d=h5_data, load_array=False)
finally:
# delete file
if file_path.exists():
Expand All @@ -43,7 +43,7 @@ def test_lazy_load_hdf5_is_array(time, data, convert_flag):
f.create_dataset('data', data=data)
# get the tsd
h5_data = h5py.File(file_path, 'r')["data"]
tsd = nap.Tsd(t=time, d=h5_data, to_numpy_array=convert_flag)
tsd = nap.Tsd(t=time, d=h5_data, load_array=convert_flag)
if convert_flag:
assert isinstance(tsd.d, np.ndarray)
else:
Expand All @@ -70,7 +70,7 @@ def test_lazy_load_hdf5_apply_func(time, data, func,cls):
# get the tsd
h5_data = h5py.File(file_path, 'r')["data"]
# lazy load and apply function
res = func(cls(t=time, d=h5_data, to_numpy_array=False))
res = func(cls(t=time, d=h5_data, load_array=False))
assert isinstance(res, cls)
assert isinstance(res.d, np.ndarray)
finally:
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_lazy_load_hdf5_apply_method(time, data, method_name, args, cls):
# get the tsd
h5_data = h5py.File(file_path, 'r')["data"]
# lazy load and apply function
tsd = cls(t=time, d=h5_data, to_numpy_array=False)
tsd = cls(t=time, d=h5_data, load_array=False)
func = getattr(tsd, method_name)
out = func(*args)
assert isinstance(out.d, np.ndarray)
Expand Down Expand Up @@ -135,7 +135,7 @@ def test_lazy_load_hdf5_apply_method_tsd_specific(time, data, method_name, args,
# get the tsd
h5_data = h5py.File(file_path, 'r')["data"]
# lazy load and apply function
tsd = nap.Tsd(t=time, d=h5_data, to_numpy_array=False)
tsd = nap.Tsd(t=time, d=h5_data, load_array=False)
func = getattr(tsd, method_name)
assert isinstance(func(*args), expected_out_type)
finally:
Expand All @@ -159,7 +159,7 @@ def test_lazy_load_hdf5_apply_method_tsdframe_specific(time, data, method_name,
# get the tsd
h5_data = h5py.File(file_path, 'r')["data"]
# lazy load and apply function
tsd = nap.TsdFrame(t=time, d=h5_data, to_numpy_array=False)
tsd = nap.TsdFrame(t=time, d=h5_data, load_array=False)
func = getattr(tsd, method_name)
assert isinstance(func(*args), expected_out_type)
finally:
Expand All @@ -177,7 +177,7 @@ def test_lazy_load_hdf5_tsdframe_loc():
# get the tsd
h5_data = h5py.File(file_path, 'r')["data"]
# lazy load and apply function
tsd = nap.TsdFrame(t=np.arange(data.shape[0]), d=h5_data, to_numpy_array=False).loc[1]
tsd = nap.TsdFrame(t=np.arange(data.shape[0]), d=h5_data, load_array=False).loc[1]
assert isinstance(tsd, nap.Tsd)
assert all(tsd.d == np.array([1, 3, 5, 7, 9]))

Expand Down

0 comments on commit 57b9a1e

Please sign in to comment.