YeoLab / bento-tools

A Python toolkit for subcellular analysis of spatial transcriptomics data
https://bento-tools.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
70 stars 6 forks source link

`_sjoin_shapes` fails to replace NaNs when '' is not already in column category #163

Open nklkhlr opened 2 weeks ago

nklkhlr commented 2 weeks ago

I noticed that bento.io.prep fails inside _sjoin_shapes (line 119 in bento.io._index.py) with

TypeError: Cannot setitem on a Categorical with a new category (), set the categories first 

if '' is not already in the shape_key column and it contains NaNs.

I added the following simple check between lines 123 and 124 to fix it:

if '' not in parent_shape[shape_key].cat.categories:
    parent_shape[shape_key] = parent_shape[shape_key].cat.add_categories([""])
ckmah commented 2 weeks ago

Thank you for reporting the bug! Will include in next update for sure.