Repository: SpikeInterface/spikeinterface

Issue:
Type mismatch in upgrading to 0.102.3
Hi,
I've recently upgraded from version 0.101.2 to 0.102.3, and now I'm encountering a type mismatch error during motion correction (below). I'm using the same data that I previously sorted, so I know the issue isn't with my data. I would appreciate any guidance on what I might be missing. 

Thank you!,
Ali

```
 File "C:\GitHub\ePhys\spikeSorting\mna_sorting\sorting.py", line 94, in check_for_drifts
    recording_corrected, motion, motion_info = si.correct_motion(
  File "C:\Users\mna\.conda\envs\spikeSorting\lib\site-packages\spikeinterface\preprocessing\motion.py", line 557, in correct_motion
    recording_corrected = interpolate_motion(recording, motion, **interpolate_motion_kwargs)
  File "C:\Users\mna\.conda\envs\spikeSorting\lib\site-packages\spikeinterface\core\core_tools.py", line 35, in source_class_or_dict_of_sources_classes
    return source_class(*args, **kwargs)
  File "C:\Users\mna\.conda\envs\spikeSorting\lib\site-packages\spikeinterface\sortingcomponents\motion\motion_interpolation.py", line 403, in __init__
    raise ValueError(f"Can't interpolate traces of recording with non-floating dtype={recording.dtype=}.")
ValueError: Can't interpolate traces of recording with non-floating dtype=recording.dtype=dtype('int16').
```

Discussion:

Fix (patch):
diff --git a/src/spikeinterface/preprocessing/motion.py b/src/spikeinterface/preprocessing/motion.py
index de764fdfa..84b212f7f 100644
--- a/src/spikeinterface/preprocessing/motion.py
+++ b/src/spikeinterface/preprocessing/motion.py
@@ -443,9 +443,6 @@ def compute_motion(
     t1 = time.perf_counter()
     run_times["estimate_motion"] = t1 - t0
 
-    if recording.get_dtype().kind != "f":
-        recording = recording.astype("float32")
-
     motion_info = dict(
         parameters=parameters,
         run_times=run_times,
@@ -554,6 +551,9 @@ def correct_motion(
         **job_kwargs,
     )
 
+    if recording.get_dtype().kind != "f":
+        recording = recording.astype("float32")
+
     recording_corrected = interpolate_motion(recording, motion, **interpolate_motion_kwargs)
 
     if not output_motion and not output_motion_info:


Test changes:
diff --git a/src/spikeinterface/preprocessing/tests/test_motion.py b/src/spikeinterface/preprocessing/tests/test_motion.py
index fa0ac1b12..a7e1263a9 100644
--- a/src/spikeinterface/preprocessing/tests/test_motion.py
+++ b/src/spikeinterface/preprocessing/tests/test_motion.py
@@ -32,6 +32,13 @@ def test_estimate_and_correct_motion(create_cache_folder):
     assert motion_info_loaded["motion"] == motion_info["motion"]
 
 
+def test_estimate_and_correct_motion_int():
+
+    rec = generate_recording(durations=[30.0], num_channels=12).astype(int)
+    rec_corrected = correct_motion(rec, estimate_motion_kwargs={"win_step_um": 50, "win_scale_um": 100})
+    assert rec_corrected.get_dtype().kind == "f"
+
+
 def test_get_motion_parameters_preset():
     from pprint import pprint