From 694c8d0b6453ffd820170a3a70e1c80892781af9 Mon Sep 17 00:00:00 2001 From: Efdix <1398475174@qq.com> Date: Tue, 30 Dec 2025 02:01:10 +0800 Subject: [PATCH] Fix KeyError in statistical analysis helper for large datasets --- .../src/core/methods/cpdb_statistical_analysis_helper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py b/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py index f03d2e4e..e12652c7 100755 --- a/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py +++ b/cellphonedb/src/core/methods/cpdb_statistical_analysis_helper.py @@ -782,7 +782,10 @@ def add_multidata_and_means_to_counts(counts: pd.DataFrame, genes: pd.DataFrame, counts_relations = counts[['id_multidata', 'ensembl', 'gene_name', 'hgnc_symbol']].copy() - counts.set_index('id_multidata', inplace=True, drop=True) + # Manually set index to avoid issues with large DataFrames and set_index + counts.index = counts['id_multidata'] + counts.index.name = 'id_multidata' + counts = counts[cells_names] if np.any(counts.dtypes.values != np.dtype('float32')): counts = counts.astype(np.float32)