From 65b2a7d0ea642132a7a5fcb5a5199b675f092e0b Mon Sep 17 00:00:00 2001 From: Ben Dichter Date: Wed, 21 Feb 2024 19:04:30 -0500 Subject: [PATCH] allow for TimeSeries with just timestamps specified (#1848) Co-authored-by: Oliver Ruebel --- src/pynwb/testing/mock/base.py | 4 +++- tests/unit/test_mock.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/pynwb/testing/mock/base.py b/src/pynwb/testing/mock/base.py index 45b95fc08..39617fe11 100644 --- a/src/pynwb/testing/mock/base.py +++ b/src/pynwb/testing/mock/base.py @@ -15,7 +15,7 @@ def mock_TimeSeries( conversion: float = 1.0, timestamps=None, starting_time: Optional[float] = None, - rate: Optional[float] = 10.0, + rate: Optional[float] = None, comments: str = "no comments", description: str = "no description", control=None, @@ -24,6 +24,8 @@ def mock_TimeSeries( nwbfile: Optional[NWBFile] = None, offset=0., ) -> TimeSeries: + if timestamps is None and rate is None: + rate = 10.0 # Hz time_series = TimeSeries( name=name or name_generator("TimeSeries"), data=data if data is not None else np.array([1, 2, 3, 4]), diff --git a/tests/unit/test_mock.py b/tests/unit/test_mock.py index d24e47551..72174f018 100644 --- a/tests/unit/test_mock.py +++ b/tests/unit/test_mock.py @@ -90,6 +90,17 @@ def test_mock(mock_function): mock_function() +def test_mock_TimeSeries_w_timestamps(): + ts = mock_TimeSeries(timestamps=[0, 1, 2, 3]) + assert ts.timestamps is not None + assert len(ts.timestamps) == 4 + + +def test_mock_TimeSeries_w_no_time(): + ts = mock_TimeSeries() + assert ts.rate == 10.0 + + @pytest.mark.parametrize("mock_function", mock_functions) def test_mock_write(mock_function, tmp_path): if mock_function is mock_NWBFile: