Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plot.py #93

Closed
wants to merge 1 commit into from
Closed

Update plot.py #93

wants to merge 1 commit into from

Conversation

milescsmith
Copy link

Fixes KeyError: [...] not in index when running celltypist.plot.dotplot()

FIX: `KeyError: [...] not in index` with dotplot()
@ChuanXu1
Copy link
Collaborator

ChuanXu1 commented Nov 6, 2023

@milescsmith, can you provide more details on why this change is needed? Thank you!

@milescsmith
Copy link
Author

Sure. The problem is that if prediction_order is not passed to celltypist.plot.dotplot() (and thus to celltypist.plot._get_fraction_prob_df()), prediction_order is set to all possible categories in the passed AnnotationResult.predicted_labels; however, the dot_color_df is derived from the sliced pred = predictions.predicted_labels[use_as_prediction], so that by the time you get to dot_color_df = dot_color_df.loc[prediction_order], the values in prediction_order may be larger than the possible values in dot_color_df and thus _get_fraction_prob_df() and dotplot() fail due to a KeyError. The bit of code I added ensures the values match or that prediction_order is a subset.

@ChuanXu1
Copy link
Collaborator

@milescsmith, I think dot_color_df is not sliced, so their values should be matched. Do you any code to produce the scenario you mentioned?

@milescsmith milescsmith closed this by deleting the head repository Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants