Skip to content

Commit afc45b5

Browse files
Fix indexing in fate_bias function and update DataFrame concatenation method
- Changed indexing from clusters[knn.flatten()] to clusters.iloc[knn.flatten()] for correct row selection in fate_bias function. - Updated DataFrame concatenation from pd.merge to pd.concat for improved performance and clarity.
1 parent b8f5aa3 commit afc45b5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

dynamo/prediction/fate.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def fate_bias(
524524
else:
525525
_, knn = nbrs.kneighbors(X[knn.flatten(), :])
526526

527-
fate_prob = clusters[knn.flatten()].value_counts() / len(knn.flatten())
527+
fate_prob = clusters.iloc[knn.flatten()].value_counts() / len(knn.flatten())
528528
if source_groups is not None:
529529
source_p = fate_prob[source_groups].sum()
530530
if 1 > source_p > 0:
@@ -542,7 +542,7 @@ def fate_bias(
542542
walk_back_steps += 1
543543

544544
if any(indices - 1 < 0):
545-
pred_dict[i] = clusters[knn.flatten()].value_counts() * np.nan
545+
pred_dict[i] = clusters.iloc[knn.flatten()].value_counts() * np.nan
546546
break
547547

548548
if hasattr(nbrs, "query"):
@@ -559,8 +559,10 @@ def fate_bias(
559559
indices = indices - 1
560560

561561
bias = pd.DataFrame(pred_dict).T
562+
if isinstance(bias.columns, pd.CategoricalIndex):
563+
bias.columns = bias.columns.astype(object)
562564
conf = pd.DataFrame({"confidence": confidence}, index=bias.index)
563-
bias = pd.merge(conf, bias, left_index=True, right_index=True)
565+
bias = pd.concat([conf, bias], axis=1)
564566

565567
if cell_indx is not None:
566568
bias.index = cell_indx

0 commit comments

Comments
 (0)