From b73af39f6fa4cba311c3da1d15804c14d759142c Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Wed, 4 Jun 2025 10:28:24 -0600 Subject: [PATCH 1/2] preprocessing filter --- src/spikeinterface/preprocessing/filter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/spikeinterface/preprocessing/filter.py b/src/spikeinterface/preprocessing/filter.py index 42b7090c0d..a702106950 100644 --- a/src/spikeinterface/preprocessing/filter.py +++ b/src/spikeinterface/preprocessing/filter.py @@ -399,6 +399,10 @@ def causal_filter( def fix_dtype(recording, dtype): + """ + Many preprocessors access scipy functions (e.g. filter) that fail silently with unsigned dtypes. + This function fixes the dtype to be signed if it is unsigned. + """ if dtype is None: dtype = recording.get_dtype() dtype = np.dtype(dtype) From 16deb76f28b2868a48a03a6540e123cfbe1815dd Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Wed, 4 Jun 2025 14:20:25 -0600 Subject: [PATCH 2/2] improved in zach direction --- src/spikeinterface/preprocessing/filter.py | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/preprocessing/filter.py b/src/spikeinterface/preprocessing/filter.py index a702106950..acc780e4fa 100644 --- a/src/spikeinterface/preprocessing/filter.py +++ b/src/spikeinterface/preprocessing/filter.py @@ -400,8 +400,27 @@ def causal_filter( def fix_dtype(recording, dtype): """ - Many preprocessors access scipy functions (e.g. filter) that fail silently with unsigned dtypes. - This function fixes the dtype to be signed if it is unsigned. + Fix and validate dtype for preprocessing operations. + + This function performs three operations: + * If no dtype is provided, infers it from the recording + * Converts the dtype to a numpy.dtype object + * Converts unsigned dtypes to their signed equivalents + + Many preprocessors use scipy functions (e.g., filtering) that fail + silently with unsigned dtypes, so conversion to signed types is necessary. + + Parameters + ---------- + recording : Recording + The recording object to get dtype from if none provided + dtype : numpy.dtype or None + The desired dtype. If None, uses recording's dtype + + Returns + ------- + numpy.dtype + A validated numpy dtype, converted to signed if originally unsigned """ if dtype is None: dtype = recording.get_dtype()