diff --git a/elephant/statistics.py b/elephant/statistics.py index bb456ac02..519c4c2fb 100644 --- a/elephant/statistics.py +++ b/elephant/statistics.py @@ -760,14 +760,13 @@ def instantaneous_rate(spiketrains, sampling_period, kernel='auto', TypeError * If `spiketrain` is not an instance of :class:`neo.core.SpikeTrain`. * If `sampling_period` is not a `pq.Quantity`. - * If `sampling_period` is not larger than zero. * If `kernel` is neither instance of :mod:`elephant.kernels` nor string 'auto'. * If `cutoff` is neither `float` nor `int`. * If `t_start` and `t_stop` are neither None nor a `pq.Quantity`. * If `trim` is not `bool`. ValueError - * If `sampling_period` is smaller than zero. + * If `sampling_period` is not larger than zero. * If `kernel` is 'auto' and the function was unable to calculate optimal kernel width for instantaneous rate from input data. * If `kernel` length is larger than binned spiketrain length @@ -987,9 +986,9 @@ def optimal_kernel(st): raise TypeError(f"The 'sampling_period' must be a time Quantity." f"Found: {type(sampling_period)}") - if sampling_period.magnitude < 0: + if sampling_period.magnitude <= 0: raise ValueError(f"The 'sampling_period' ({sampling_period}) " - f"must be non-negative.") + f"must be larger than zero.") if not (isinstance(kernel, kernels.Kernel) or kernel == 'auto'): raise TypeError(f"'kernel' must be instance of class " diff --git a/elephant/test/test_statistics.py b/elephant/test/test_statistics.py index fde6d54e8..21942cdd5 100644 --- a/elephant/test/test_statistics.py +++ b/elephant/test/test_statistics.py @@ -565,6 +565,16 @@ def test_instantaneous_rate_errors(self): ValueError, statistics.instantaneous_rate, spiketrains=self.spike_train, kernel=self.kernel, sampling_period=-0.01 * pq.ms) + self.assertRaisesRegex( # sampling period is == 0 + ValueError, r"must be larger than zero", + statistics.instantaneous_rate, + spiketrains=self.spike_train, kernel=self.kernel, + sampling_period=0 * pq.ms) + self.assertRaisesRegex( # sampling period is == 0, list input + ValueError, r"must be larger than zero", + statistics.instantaneous_rate, + spiketrains=[self.spike_train, self.spike_train], + kernel=self.kernel, sampling_period=0 * pq.s) self.assertRaises( # no kernel or kernel='auto' TypeError, statistics.instantaneous_rate, spiketrains=self.spike_train, sampling_period=0.01 * pq.ms,