diff --git a/elephant/signal_processing.py b/elephant/signal_processing.py index 9a09f3fa8..1e8fe8631 100644 --- a/elephant/signal_processing.py +++ b/elephant/signal_processing.py @@ -167,7 +167,7 @@ def zscore(signal, inplace=True): for sig in signal: # Perform inplace operation only if array is of dtype float. # Otherwise, raise an error. - if inplace and not np.issubdtype(float, sig.dtype): + if inplace and not np.issubdtype(sig.dtype, np.floating): raise ValueError(f"Cannot perform inplace operation as the " f"signal dtype is not float. Source: {sig.name}") diff --git a/elephant/test/test_signal_processing.py b/elephant/test/test_signal_processing.py index 303e3cdfd..83e51d4f6 100644 --- a/elephant/test/test_signal_processing.py +++ b/elephant/test/test_signal_processing.py @@ -401,7 +401,7 @@ def test_zscore_list_inplace(self): self.assertIs(result[0], signal_list[0]) self.assertIs(result[1], signal_list[1]) - def test_wrong_input(self): + def test_z_score_wrong_input(self): # wrong type self.assertRaises(TypeError, elephant.signal_processing.zscore, signal=[1, 2] * pq.uV) @@ -411,6 +411,23 @@ def test_wrong_input(self): self.assertRaises(ValueError, elephant.signal_processing.zscore, signal=[asig1, asig2]) + def test_z_score_np_float32_64(self): + """ + Regression test: Inplace operations for z_score failed when using + np.float32 or np.float64 types. + See Issue #591. + https://github.com/NeuralEnsemble/elephant/issues/591 + """ + test_types = (np.float32, np.float64) + for test_type in test_types: + with self.subTest(test_type): + signal = neo.AnalogSignal(self.test_seq1, units='mV', + t_start=0. * pq.ms, + sampling_rate=1000. * pq.Hz, + dtype=test_type) + # This should not raise a ValueError + elephant.signal_processing.zscore(signal, inplace=True) + class ButterTestCase(unittest.TestCase):