fix(labels): defer float-dtype rejection to spatialdata's model validation - #758
Merged
Conversation
…ation spatialdata 0.8 rejects non-integer label rasters at the model boundary (parse / SpatialData construction / __setitem__) with a clear, actionable message. This makes _render_labels' own float-dtype guard (added in #606, when spatialdata 0.5 still accepted float labels) redundant dead code: a validly built element can no longer reach the renderer with a float dtype. - Remove the redundant render-time guard; trust the upstream boundary. - Drop test_render_labels_rejects_float_dtype (asserts an unreachable render-time scenario; upstream now raises earlier at parse). - Rewrite the measure_obs float test to exercise _stream_label_centroid_stats directly (where the integer-valued-float -> int cast lives), since a float labels element can no longer be placed in a SpatialData. The helper's float->int cast is kept as cheap, correct-by-construction robustness for any integer-valued float raster passed to it directly.
timtreis
added a commit
that referenced
this pull request
Aug 7, 2026
#758 removed the render-time float-dtype guard on the assumption that spatialdata always rejects float labels at the model boundary. That only holds on spatialdata >=0.8; the library still supports spatialdata >=0.3, where float labels parse fine and would again crash deep in skimage with a cryptic TypeError (#606). Restore the guard so the clear error holds across the whole supported range. - render.py: re-add the float-dtype ValueError guard. - test_render_labels.py: re-add test_render_labels_rejects_float_dtype in a version-agnostic form (assert an "integer dtype" error is raised at whichever layer enforces it: spatialdata on >=0.8, our guard on <0.8). - test_render_shapes.py: sort queried shapes before render so the overlap draw order (and the baseline) is stable across spatialdata's query-order change in 0.8; regenerate the baseline accordingly. The measure_obs float coverage stays as the version-independent _stream_label_centroid_stats unit test added in #758.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
mainis red on 4 label-related tests, all caused by spatialdata 0.8:test_render_labels_rejects_float_dtype[float16/32/64]test_utils.py::TestMeasureObs::test_float_dtype_labels_supportedThey fail at test setup, with:
Root cause
#606 (filed against spatialdata 0.5, where
Labels2DModel.parsestill accepted float32) added a float-dtype guard inside_render_labels. spatialdata 0.8 moved that validation to the model boundary —parse(),SpatialData(...), andsd[k] = ...all now reject non-integer label rasters with a clear, actionable message (verified: the only way to obtain a float-labels element is a raw.datamutation, which is unsupported).Consequences:
Changes
_render_labels; defer to spatialdata's boundary validation (interop over duplication).test_render_labels_rejects_float_dtype— it asserts an unreachable render-time scenario.measure_obsfloat test to exercise_stream_label_centroid_statsdirectly (where the integer-valued-float → int cast actually lives), asserting a float raster yields exactly what its integer counterpart yields. The cast itself is kept as cheap correct-by-construction robustness.Not in scope
The 5th
mainfailure —Shapes_…random_shuffling(visual) — is a separate, deterministic upstream draw-order drift (colors still map correctly; only overlap z-order changed). Tracked for its own baseline-refresh PR, not folded in here.Testing
test_utils.py(140) andtest_render_labels.pypass locally.