@@ -1472,12 +1472,12 @@ def _type_check_params(param_dict: dict[str, Any], element_type: str) -> dict[st
14721472
14731473 if element_type == "images" :
14741474 param_dict ["element" ] = [element ] if element is not None else list (param_dict ["sdata" ].images .keys ())
1475- if element_type == "labels" :
1475+ elif element_type == "labels" :
14761476 param_dict ["element" ] = [element ] if element is not None else list (param_dict ["sdata" ].labels .keys ())
1477- if element_type == "shapes" :
1478- param_dict ["element" ] = [element ] if element is not None else list (param_dict ["sdata" ].shapes .keys ())
1479- if element_type == "points" :
1477+ elif element_type == "points" :
14801478 param_dict ["element" ] = [element ] if element is not None else list (param_dict ["sdata" ].points .keys ())
1479+ elif element_type == "shapes" :
1480+ param_dict ["element" ] = [element ] if element is not None else list (param_dict ["sdata" ].shapes .keys ())
14811481
14821482 if (channel := param_dict .get ("channel" )) is not None and not isinstance (channel , (list , str , int )):
14831483 raise TypeError ("Parameter 'channel' must be a string, an integer, or a list of strings or integers." )
@@ -1493,10 +1493,14 @@ def _type_check_params(param_dict: dict[str, Any], element_type: str) -> dict[st
14931493 if (contour_px := param_dict .get ("contour_px" )) and not isinstance (contour_px , int ):
14941494 raise TypeError ("Parameter 'contour_px' must be an integer." )
14951495
1496- if (color := param_dict .get ("color" )) and element_type in ["shapes" , "points" , "labels" ]:
1496+ if (color := param_dict .get ("color" )) and element_type in {
1497+ "shapes" ,
1498+ "points" ,
1499+ "labels" ,
1500+ }:
14971501 if not isinstance (color , str ):
14981502 raise TypeError ("Parameter 'color' must be a string." )
1499- if element_type in [ "shapes" , "points" ] :
1503+ if element_type in { "shapes" , "points" } :
15001504 if colors .is_color_like (color ):
15011505 logger .info ("Value for parameter 'color' appears to be a color, using it as such." )
15021506 param_dict ["col_for_color" ] = None
@@ -1667,6 +1671,10 @@ def _validate_label_render_params(
16671671
16681672 element_params : dict [str , dict [str , Any ]] = {}
16691673 for el in param_dict ["element" ]:
1674+
1675+ # ensure that the element exists in the SpatialData object
1676+ _ = param_dict ["sdata" ][el ]
1677+
16701678 element_params [el ] = {}
16711679 element_params [el ]["na_color" ] = param_dict ["na_color" ]
16721680 element_params [el ]["cmap" ] = param_dict ["cmap" ]
@@ -1721,6 +1729,10 @@ def _validate_points_render_params(
17211729
17221730 element_params : dict [str , dict [str , Any ]] = {}
17231731 for el in param_dict ["element" ]:
1732+
1733+ # ensure that the element exists in the SpatialData object
1734+ _ = param_dict ["sdata" ][el ]
1735+
17241736 element_params [el ] = {}
17251737 element_params [el ]["na_color" ] = param_dict ["na_color" ]
17261738 element_params [el ]["cmap" ] = param_dict ["cmap" ]
@@ -1784,6 +1796,10 @@ def _validate_shape_render_params(
17841796
17851797 element_params : dict [str , dict [str , Any ]] = {}
17861798 for el in param_dict ["element" ]:
1799+
1800+ # ensure that the element exists in the SpatialData object
1801+ _ = param_dict ["sdata" ][el ]
1802+
17871803 element_params [el ] = {}
17881804 element_params [el ]["fill_alpha" ] = param_dict ["fill_alpha" ]
17891805 element_params [el ]["na_color" ] = param_dict ["na_color" ]
0 commit comments