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

render_points with column coloring throws error when there are too many points #910

Open
ziyuanzhao2000 opened this issue Mar 21, 2025 · 0 comments

Comments

@ziyuanzhao2000
Copy link

ziyuanzhao2000 commented Mar 21, 2025

Recommendation: attach a minimal working example

Minimal working example with a toy dataset:

from spatialdata.models import PointsModel
n_points=10000
coords = pd.DataFrame({'x': np.random.rand(n_points), 
                       'y': np.random.rand(n_points)})
points = PointsModel.parse(coords)
points_sdata = sd.SpatialData(points={"points": points})

obs = pd.DataFrame()
obs["instance_id"] = np.arange(n_points)
obs["region"] = "points"
obs["region"].astype("category")
obs["feature"] = np.random.rand(n_points)

table = AnnData(X=np.random.rand(n_points, 1), obs=obs)

points_sdata['table'] = TableModel.parse(table, region='points', region_key='region', instance_key='instance_id')

points_sdata.pl.render_points('points', color='feature', size=100).pl.show()

Describe the bug
Changing n_points from 10000 to 10001 and greater values gives the error: KeyError: 'feature' which is very annoying because I work with very large single cell datasets.

My assessment:
looking at this source code

if method is None:
        method = "datashader" if len(points) > 10000 else "matplotlib"

it seems that the problem is due to using the datashader backend?

@ziyuanzhao2000 ziyuanzhao2000 changed the title render_points with column coloring throws error when there are too many points render_points with column coloring throws error when there are too many points Mar 21, 2025
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

No branches or pull requests

1 participant