When attempting to plot points colored by an annotation column from table.obs, it works as expected with the matplotlib backend, but fails with a KeyError when using the datashader backend.
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File /scratch/sturmgre/projects/scverse/spatialdata-plot/.venv/lib/python3.13/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key)
3811 try:
-> [3812](https://vscode-remote+ssh-002dremote-002binh.vscode-resource.vscode-cdn.net/scratch/sturmgre/projects/scverse/spatialdata-plot/.venv/lib/python3.13/site-packages/pandas/core/indexes/base.py:3812) return self._engine.get_loc(casted_key)
3813 except KeyError as err:
File pandas/_libs/index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/hashtable_class_helper.pxi:7088, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas/_libs/hashtable_class_helper.pxi:7096, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'foo'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
Cell In[33], [line 1](vscode-notebook-cell:?execution_count=33&line=1)
----> [1](vscode-notebook-cell:?execution_count=33&line=1) sdata.pl.render_points("blobs_points", method="datashader", color="foo", table_name="table_for_points").pl.show()
File /cfs/sturmgre/projects/scverse/spatialdata-plot/src/spatialdata_plot/pl/basic.py:953, in PlotAccessor.show(self, coordinate_systems, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, na_in_legend, colorbar, wspace, hspace, ncols, frameon, figsize, dpi, fig, title, share_extent, pad_extent, ax, return_ax, save)
948 wanted_elements, wanted_points_on_this_cs, wants_points = _get_wanted_render_elements(
949 sdata, wanted_elements, params_copy, cs, "points"
950 )
952 if wanted_points_on_this_cs:
--> [953](https://vscode-remote+ssh-002dremote-002binh.vscode-resource.vscode-cdn.net/cfs/sturmgre/projects/scverse/spatialdata-plot/src/spatialdata_plot/pl/basic.py:953) _render_points(
954 sdata=sdata,
955 render_params=params_copy,
956 coordinate_system=cs,
957 ax=ax,
958 fig_params=fig_params,
959 scalebar_params=scalebar_params,
960 legend_params=legend_params,
961 )
963 elif cmd == "render_labels" and has_labels:
964 wanted_elements, wanted_labels_on_this_cs, wants_labels = _get_wanted_render_elements(
965 sdata, wanted_elements, params_copy, cs, "labels"
966 )
File /cfs/sturmgre/projects/scverse/spatialdata-plot/src/spatialdata_plot/pl/render.py:593, in _render_points(sdata, render_params, coordinate_system, ax, fig_params, scalebar_params, legend_params)
590 # use datashader for the visualization of points
591 cvs = ds.Canvas(plot_width=plot_width, plot_height=plot_height, x_range=x_ext, y_range=y_ext)
--> [593](https://vscode-remote+ssh-002dremote-002binh.vscode-resource.vscode-cdn.net/cfs/sturmgre/projects/scverse/spatialdata-plot/src/spatialdata_plot/pl/render.py:593) color_by_categorical = col_for_color is not None and transformed_element[col_for_color].values.dtype in (
594 object,
595 "categorical",
596 )
597 if color_by_categorical and transformed_element[col_for_color].values.dtype == object:
598 transformed_element[col_for_color] = transformed_element[col_for_color].astype("category")
File /scratch/sturmgre/projects/scverse/spatialdata-plot/.venv/lib/python3.13/site-packages/dask/dataframe/core.py:4955, in DataFrame.__getitem__(self, key)
4952 return self.loc[key]
4954 # error is raised from pandas
-> [4955](https://vscode-remote+ssh-002dremote-002binh.vscode-resource.vscode-cdn.net/scratch/sturmgre/projects/scverse/spatialdata-plot/.venv/lib/python3.13/site-packages/dask/dataframe/core.py:4955) meta = self._meta[_extract_meta(key)]
4956 dsk = partitionwise_graph(operator.getitem, name, self, key)
4957 graph = HighLevelGraph.from_collections(name, dsk, dependencies=[self])
File /scratch/sturmgre/projects/scverse/spatialdata-plot/.venv/lib/python3.13/site-packages/pandas/core/frame.py:4107, in DataFrame.__getitem__(self, key)
4105 if self.columns.nlevels > 1:
4106 return self._getitem_multilevel(key)
-> [4107](https://vscode-remote+ssh-002dremote-002binh.vscode-resource.vscode-cdn.net/scratch/sturmgre/projects/scverse/spatialdata-plot/.venv/lib/python3.13/site-packages/pandas/core/frame.py:4107) indexer = self.columns.get_loc(key)
4108 if is_integer(indexer):
4109 indexer = [indexer]
File /scratch/sturmgre/projects/scverse/spatialdata-plot/.venv/lib/python3.13/site-packages/pandas/core/indexes/base.py:3819, in Index.get_loc(self, key)
3814 if isinstance(casted_key, slice) or (
3815 isinstance(casted_key, abc.Iterable)
3816 and any(isinstance(x, slice) for x in casted_key)
3817 ):
3818 raise InvalidIndexError(key)
-> [3819](https://vscode-remote+ssh-002dremote-002binh.vscode-resource.vscode-cdn.net/scratch/sturmgre/projects/scverse/spatialdata-plot/.venv/lib/python3.13/site-packages/pandas/core/indexes/base.py:3819) raise KeyError(key) from err
3820 except TypeError:
3821 # If we have a listlike key, _check_indexing_error will raise
3822 # InvalidIndexError. Otherwise we fall through and re-raise
3823 # the TypeError.
3824 self._check_indexing_error(key)
KeyError: 'foo'
When attempting to plot points colored by an annotation column from table.obs, it works as expected with the matplotlib backend, but fails with a KeyError when using the datashader backend.
Steps to reproduce
Stacktrace
Session Info