Conversation
Cover case where slide does not contain all available id_key in adata object
Thanks for your commitment. We've tested it based on your suggestion but we didn't reproduce your bug. Could you provide your data to 1143715389@qq.com if possible? |
1. Context
2. Reason
When
library_keydoes not contain all values ofid_key, certain combinations may be missing from the resulting DataFrame.For example, if 'Acinar cell' exists in other slides but not in slide
#3, then:will omit the
(library_key='#3', id_key='Acinar cell')row entirely.As a result, trying to access:
for that combination raises a KeyError during list comprehension like:
3. Fix
Replace the
groupby().size().unstack().fillna(0)withpd.crosstab(..., dropna=False):This ensures all combinations, including those with zero counts, are included — preventing missing rows and avoiding KeyError.