|
64 | 64 | ) |
65 | 65 | from spatialdata._core.query.relational_query import _locate_value |
66 | 66 | from spatialdata._types import ArrayLike |
67 | | -from spatialdata.models import Image2DModel, Labels2DModel, SpatialElement, TableModel, get_table_keys |
| 67 | +from spatialdata.models import Image2DModel, Labels2DModel, SpatialElement, get_table_keys |
68 | 68 | from spatialdata.transformations.operations import get_transformation |
69 | 69 | from spatialdata.transformations.transformations import Scale, Translation |
70 | 70 | from spatialdata.transformations.transformations import Sequence as TransformSequence |
@@ -110,26 +110,30 @@ def _check_obs_var_shadow( |
110 | 110 | value_to_plot: str | None, |
111 | 111 | table_name: str | None, |
112 | 112 | ) -> None: |
113 | | - """Raise if `value_to_plot` exists in both `table.obs.columns` and `table.var_names`. |
| 113 | + """Raise if ``value_to_plot`` exists in both ``table.obs.columns`` and ``table.var_names``. |
114 | 114 |
|
115 | | - Upstream `_get_table_origins` uses an `elif` chain, so a key that lives in both |
116 | | - locations is silently resolved to `obs` — masking the user's likely intent of |
117 | | - plotting gene expression. Catch this here before any value fetch. |
| 115 | + Upstream ``_get_table_origins`` uses an ``elif`` chain, so a key that lives in |
| 116 | + both locations is silently resolved to ``obs`` — masking the user's likely |
| 117 | + intent of plotting gene expression. Catch this here before any value fetch. |
| 118 | + Any ``None`` parameter short-circuits the check. |
118 | 119 | """ |
119 | | - if value_to_plot is None or table_name is None or sdata is None or table_name not in sdata.tables: |
120 | | - return |
121 | | - table = sdata.tables[table_name] |
122 | | - if value_to_plot not in table.obs.columns or value_to_plot not in table.var_names: |
| 120 | + if ( |
| 121 | + value_to_plot is None |
| 122 | + or table_name is None |
| 123 | + or element_name is None |
| 124 | + or sdata is None |
| 125 | + or table_name not in sdata.tables |
| 126 | + ): |
123 | 127 | return |
124 | | - region = table.uns[TableModel.ATTRS_KEY][TableModel.REGION_KEY] |
125 | | - annotates_element = element_name in region if isinstance(region, list) else element_name == region |
126 | | - if not annotates_element: |
| 128 | + if table_name not in get_element_annotators(sdata, element_name): |
127 | 129 | return |
128 | | - raise ValueError( |
129 | | - f"Color key '{value_to_plot}' is ambiguous: it exists in both " |
130 | | - f"`table['{table_name}'].obs.columns` and `table['{table_name}'].var_names`. " |
131 | | - "Rename one of them (or drop the obs column) so the intended source is unambiguous." |
132 | | - ) |
| 130 | + table = sdata.tables[table_name] |
| 131 | + if value_to_plot in table.obs.columns and value_to_plot in table.var_names: |
| 132 | + raise ValueError( |
| 133 | + f"`color={value_to_plot!r}` is ambiguous: it exists in both " |
| 134 | + f"`table[{table_name!r}].obs.columns` and `table[{table_name!r}].var_names`. " |
| 135 | + "Rename one of them (or drop the obs column) so the intended source is unambiguous." |
| 136 | + ) |
133 | 137 |
|
134 | 138 |
|
135 | 139 | def _gate_palette_and_groups( |
|
0 commit comments