Skip to content

Render_points breaks with scanpy=1.10.4 #389

@ckmah

Description

@ckmah

sdata.pl.render_points() fails with scanpy=1.10.4 because the sc.get.obs_df(adata, col_for_color) getter casts col_for_color if it is a str to a list. Easy fix is cast the output to a Series since the output should always a single column in our case.

This was produced with spatialdata-plot=v0.2.7.

https://github.com/scverse/scanpy/blob/02cb8c0f04580d02ca0a691d5becc8f2fa6c2ee0/src/scanpy/get/get.py#L324C5-L324C22

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/q8/th6r292x7lsf54dm_03pn_7r0000gn/T/ipykernel_96569/361469311.py in ?()
      1 blobs = sd.datasets.blobs()
----> 2 blobs.pl.render_points(color="genes", groups="gene_a").pl.show()

/opt/homebrew/Caskroom/mambaforge/base/envs/spatialdata-stable/lib/python3.12/site-packages/spatialdata_plot/pl/basic.py in ?(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)
    931                         sdata, wanted_elements, params_copy, cs, "points"
    932                     )
    933 
    934                     if wanted_points_on_this_cs:
--> 935                         _render_points(
    936                             sdata=sdata,
    937                             render_params=params_copy,
    938                             coordinate_system=cs,

/opt/homebrew/Caskroom/mambaforge/base/envs/spatialdata-stable/lib/python3.12/site-packages/spatialdata_plot/pl/render.py in ?(sdata, render_params, coordinate_system, ax, fig_params, scalebar_params, legend_params)
    441 
    442     if col_for_color is not None:
    443         cols = sc.get.obs_df(adata, col_for_color)
    444         # maybe set color based on type
--> 445         if isinstance(cols.dtype, pd.CategoricalDtype):
    446             _maybe_set_colors(
    447                 source=adata,
    448                 target=adata,

/opt/homebrew/Caskroom/mambaforge/base/envs/spatialdata-stable/lib/python3.12/site-packages/pandas/core/generic.py in ?(self, name)
   6295             and name not in self._accessors
   6296             and self._info_axis._can_hold_identifiers_and_holds_name(name)
   6297         ):
   6298             return self[name]
-> 6299         return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'dtype'

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