From bd1ebe816944ba288362ae4eb3a05d5da6da0008 Mon Sep 17 00:00:00 2001 From: Samuel Garcia Date: Wed, 15 Jan 2025 08:59:35 +0100 Subject: [PATCH 1/2] Fix dtype for index due to csv --- src/spikeinterface/core/sortinganalyzer.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/spikeinterface/core/sortinganalyzer.py b/src/spikeinterface/core/sortinganalyzer.py index 55cbe6070a..9a5a7a99f5 100644 --- a/src/spikeinterface/core/sortinganalyzer.py +++ b/src/spikeinterface/core/sortinganalyzer.py @@ -2092,6 +2092,13 @@ def load_data(self): import pandas as pd ext_data = pd.read_csv(ext_data_file, index_col=0) + # really sad hack here because csv was a bad choice for saving a DataFrame (maybe a npy per columns would have been better) + unit_ids = self.sorting_analyzer.unit_ids + if ext_data.shape[0] == unit_ids.size: + # we force dtype to be the same as unit_ids + if ext_data.index.dtype != unit_ids.dtype: + ext_data.index = ext_data.index.astype(unit_ids.dtype) + elif ext_data_file.suffix == ".pkl": with ext_data_file.open("rb") as f: ext_data = pickle.load(f) From e3b2f16761bf3ef0a5ef579f5e44bfeed87e9ffe Mon Sep 17 00:00:00 2001 From: Garcia Samuel Date: Wed, 15 Jan 2025 09:19:01 +0100 Subject: [PATCH 2/2] Update src/spikeinterface/core/sortinganalyzer.py Co-authored-by: Alessio Buccino --- src/spikeinterface/core/sortinganalyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/sortinganalyzer.py b/src/spikeinterface/core/sortinganalyzer.py index 9a5a7a99f5..fdad87287e 100644 --- a/src/spikeinterface/core/sortinganalyzer.py +++ b/src/spikeinterface/core/sortinganalyzer.py @@ -2092,7 +2092,7 @@ def load_data(self): import pandas as pd ext_data = pd.read_csv(ext_data_file, index_col=0) - # really sad hack here because csv was a bad choice for saving a DataFrame (maybe a npy per columns would have been better) + # we need to cast the index to the unit id dtype (int or str) unit_ids = self.sorting_analyzer.unit_ids if ext_data.shape[0] == unit_ids.size: # we force dtype to be the same as unit_ids