diff --git a/src/spikeinterface/preprocessing/filter.py b/src/spikeinterface/preprocessing/filter.py index 42b7090c0d..acc780e4fa 100644 --- a/src/spikeinterface/preprocessing/filter.py +++ b/src/spikeinterface/preprocessing/filter.py @@ -399,6 +399,29 @@ def causal_filter( def fix_dtype(recording, dtype): + """ + 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() dtype = np.dtype(dtype)