Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/spikeinterface/preprocessing/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down