From 57b9a1edac749bfcbe7d495d6ad2f52972d2f5df Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Tue, 21 May 2024 14:21:38 -0400 Subject: [PATCH] renamed flag --- pynapple/core/time_series.py | 16 ++++++++-------- pynapple/io/interface_nwb.py | 6 +++--- tests/test_lazy_loading.py | 14 +++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pynapple/core/time_series.py b/pynapple/core/time_series.py index 62d551f0..41b2f77b 100644 --- a/pynapple/core/time_series.py +++ b/pynapple/core/time_series.py @@ -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): @@ -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 @@ -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 @@ -850,7 +850,7 @@ def __init__( time_units="s", time_support=None, columns=None, - to_numpy_array=True, + load_array=True, ): """ TsdFrame initializer @@ -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." @@ -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. @@ -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" diff --git a/pynapple/io/interface_nwb.py b/pynapple/io/interface_nwb.py index d1f75208..496f7368 100644 --- a/pynapple/io/interface_nwb.py +++ b/pynapple/io/interface_nwb.py @@ -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 @@ -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 @@ -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 diff --git a/tests/test_lazy_loading.py b/tests/test_lazy_loading.py index 8f90f3da..723a6035 100644 --- a/tests/test_lazy_loading.py +++ b/tests/test_lazy_loading.py @@ -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(): @@ -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: @@ -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: @@ -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) @@ -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: @@ -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: @@ -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]))