diff --git a/src/pynwb/base.py b/src/pynwb/base.py index 5514288e8..846266853 100644 --- a/src/pynwb/base.py +++ b/src/pynwb/base.py @@ -187,10 +187,12 @@ def __init__(self, **kwargs): if isinstance(timestamps, TimeSeries): timestamps.__add_link('timestamp_link', self) elif self.rate is not None: - if self.rate <= 0: + if self.rate < 0: self._error_on_new_warn_on_construct( - error_msg='Rate must be a positive value.' + error_msg='Rate must not be a negative value.' ) + elif self.rate == 0.0 and get_data_shape(data)[0] > 1: + warn('Timeseries has a rate of 0.0 Hz, but the length of the data is greater than 1.') if self.starting_time is None: # override default if rate is provided but not starting time self.starting_time = 0.0 self.starting_time_unit = self.__time_unit diff --git a/tests/unit/test_base.py b/tests/unit/test_base.py index 899628190..ad4ce6739 100644 --- a/tests/unit/test_base.py +++ b/tests/unit/test_base.py @@ -406,10 +406,12 @@ def test_get_data_in_units(self): assert_array_equal(ts.get_data_in_units(), [1., 2., 3.]) def test_non_positive_rate(self): - with self.assertRaisesWith(ValueError, 'Rate must be a positive value.'): + with self.assertRaisesWith(ValueError, 'Rate must not be a negative value.'): TimeSeries(name='test_ts', data=list(), unit='volts', rate=-1.0) - with self.assertRaisesWith(ValueError, 'Rate must be a positive value.'): - TimeSeries(name='test_ts1', data=list(), unit='volts', rate=0.0) + + with self.assertWarnsWith(UserWarning, + 'Timeseries has a rate of 0.0 Hz, but the length of the data is greater than 1.'): + TimeSeries(name='test_ts1', data=[1, 2, 3], unit='volts', rate=0.0) def test_file_with_non_positive_rate_in_construct_mode(self): """Test that UserWarning is raised when rate is 0 or negative @@ -419,7 +421,7 @@ def test_file_with_non_positive_rate_in_construct_mode(self): parent=None, object_id="test", in_construct_mode=True) - with self.assertWarnsWith(warn_type=UserWarning, exc_msg='Rate must be a positive value.'): + with self.assertWarnsWith(warn_type=UserWarning, exc_msg='Rate must not be a negative value.'): obj.__init__( name="test_ts", data=list(),