Skip to content

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

Open
@ziyuanzhao2000

Description

@ziyuanzhao2000

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions