Skip to content

Commit bb4c2e2

Browse files
committed
Trim comments, flatten nested if in EntityID workaround
Address simplify-review nits: cs-filter comments were over-explaining what the code did; collapse to single-line WHY. Flatten the nested collision/Range-index check into an elif cascade.
1 parent 9c5fb8f commit bb4c2e2

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

‎src/spatialdata_plot/pl/render.py‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,8 @@ def _render_shapes(
411411

412412
_check_obs_var_shadow(sdata, element, col_for_color, render_params.table_name)
413413

414-
# filter_tables=False: when table_name is set, the cs-level table copy is
415-
# redundant — join_spatialelement_table below produces a per-element table
416-
# that overwrites sdata_filt[table_name]. Skipping the upstream copy avoids
417-
# materializing the full sparse .X for large consolidated tables.
414+
# filter_tables=False: join_spatialelement_table below overwrites the table,
415+
# so the cs-level sparse copy is wasted work.
418416
sdata_filt = sdata.filter_by_coordinate_system(
419417
coordinate_system=coordinate_system,
420418
filter_tables=False,
@@ -437,11 +435,12 @@ def _render_shapes(
437435
_obs = sdata[table_name].obs
438436
_saved_index_name = _obs.index.name
439437
_saved_index: pd.Index | None = None
440-
if _saved_index_name is not None and _saved_index_name in _obs.columns:
438+
_name_collides = _saved_index_name is not None and _saved_index_name in _obs.columns
439+
if _name_collides and not isinstance(_obs.index, pd.RangeIndex):
440+
_saved_index = _obs.index
441+
_obs.index = pd.RangeIndex(len(_obs))
442+
elif _name_collides:
441443
_obs.index.name = None
442-
if not isinstance(_obs.index, pd.RangeIndex):
443-
_saved_index = _obs.index
444-
_obs.index = pd.RangeIndex(len(_obs))
445444

446445
try:
447446
element_dict, joined_table = join_spatialelement_table(
@@ -1761,9 +1760,8 @@ def _render_labels(
17611760

17621761
_check_obs_var_shadow(sdata, element, col_for_color, table_name)
17631762

1764-
# filter_tables=False: see _render_shapes — match_table_to_element below
1765-
# (via _set_color_source_vec → get_values) already filters to the single
1766-
# element, so the upstream cs-level sparse copy is wasted work.
1763+
# filter_tables=False: match_table_to_element below already filters per
1764+
# element, so the cs-level sparse copy is wasted work.
17671765
sdata_filt = sdata.filter_by_coordinate_system(
17681766
coordinate_system=coordinate_system,
17691767
filter_tables=False,

0 commit comments

Comments
 (0)