File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ def _get_category_colors(
3232 Parameters
3333 ----------
3434 adata
35- AnnData object to get colors from.
35+ AnnData object to get colors from (must be AnnData, not a list) .
3636 label_key
3737 Key in .obs storing the categorical annotation.
3838 categories
@@ -41,11 +41,20 @@ def _get_category_colors(
4141 Returns
4242 -------
4343 List of colors corresponding to each category.
44+
45+ Raises
46+ ------
47+ TypeError
48+ If adata is not None and not an AnnData object.
4449 """
50+ if adata is not None and not hasattr (adata , "uns" ):
51+ msg = f"Expected AnnData object, got { type (adata ).__name__ } ."
52+ raise TypeError (msg )
53+
4554 colors_key = f"{ label_key } _colors"
4655 colors_dict : dict [str , str ] = {}
4756
48- if adata is not None and hasattr ( adata , "uns" ) and colors_key in adata .uns :
57+ if adata is not None and colors_key in adata .uns :
4958 full_categories = adata .obs [label_key ].cat .categories
5059 full_colors = adata .uns [colors_key ]
5160 for i , cat in enumerate (full_categories ):
You can’t perform that action at this time.
0 commit comments