@@ -334,35 +334,21 @@ def _get_cs_contents(sdata: sd.SpatialData) -> pd.DataFrame:
334334 """Check which coordinate systems contain which elements and return that info."""
335335 cs_mapping = _get_coordinate_system_mapping (sdata )
336336 content_flags = ["has_images" , "has_labels" , "has_points" , "has_shapes" ]
337- cs_contents = pd .DataFrame (columns = ["cs" ] + content_flags )
338337
338+ rows = []
339339 for cs_name , element_ids in cs_mapping .items ():
340- # determine if coordinate system has the respective elements
341- cs_has_images = any (e in sdata .images for e in element_ids )
342- cs_has_labels = any (e in sdata .labels for e in element_ids )
343- cs_has_points = any (e in sdata .points for e in element_ids )
344- cs_has_shapes = any (e in sdata .shapes for e in element_ids )
345-
346- cs_contents = pd .concat (
347- [
348- cs_contents ,
349- pd .DataFrame (
350- {
351- "cs" : cs_name ,
352- "has_images" : [cs_has_images ],
353- "has_labels" : [cs_has_labels ],
354- "has_points" : [cs_has_points ],
355- "has_shapes" : [cs_has_shapes ],
356- }
357- ),
358- ]
340+ rows .append (
341+ {
342+ "cs" : cs_name ,
343+ "has_images" : any (e in sdata .images for e in element_ids ),
344+ "has_labels" : any (e in sdata .labels for e in element_ids ),
345+ "has_points" : any (e in sdata .points for e in element_ids ),
346+ "has_shapes" : any (e in sdata .shapes for e in element_ids ),
347+ }
359348 )
360349
361- cs_contents ["has_images" ] = cs_contents ["has_images" ].astype ("bool" )
362- cs_contents ["has_labels" ] = cs_contents ["has_labels" ].astype ("bool" )
363- cs_contents ["has_points" ] = cs_contents ["has_points" ].astype ("bool" )
364- cs_contents ["has_shapes" ] = cs_contents ["has_shapes" ].astype ("bool" )
365-
350+ cs_contents = pd .DataFrame (rows , columns = ["cs" ] + content_flags )
351+ cs_contents [content_flags ] = cs_contents [content_flags ].astype ("bool" )
366352 return cs_contents
367353
368354
@@ -2102,7 +2088,7 @@ def _get_elements_to_be_rendered(
21022088 ImageRenderParams | LabelsRenderParams | PointsRenderParams | ShapesRenderParams ,
21032089 ]
21042090 ],
2105- cs_contents : pd .DataFrame ,
2091+ cs_index : pd .DataFrame ,
21062092 cs : str ,
21072093) -> list [str ]:
21082094 """
@@ -2112,23 +2098,23 @@ def _get_elements_to_be_rendered(
21122098 ----------
21132099 render_cmds
21142100 List of tuples containing the commands and their respective parameters.
2115- cs_contents
2116- The dataframe indicating for each coordinate system which SpatialElements it contains .
2101+ cs_index
2102+ The cs_contents dataframe indexed by the "cs" column .
21172103 cs
2118- The name of the coordinate system to query cs_contents for.
2104+ The name of the coordinate system to query cs_index for.
21192105
21202106 Returns
21212107 -------
21222108 List of names of the SpatialElements to be rendered in the plot.
21232109 """
21242110 elements_to_be_rendered : list [str ] = []
21252111
2126- cs_query = cs_contents . query ( f"cs == ' { cs } '" )
2112+ cs_row = cs_index . loc [ cs ] if cs in cs_index . index else None
21272113
21282114 for cmd , params in render_cmds :
21292115 key = _RENDER_CMD_TO_CS_FLAG .get (cmd )
2130- if key and cs_query [key ][ 0 ]:
2131- elements_to_be_rendered += [ params .element ]
2116+ if key and cs_row is not None and cs_row [key ]:
2117+ elements_to_be_rendered . append ( params .element )
21322118
21332119 return elements_to_be_rendered
21342120
0 commit comments