Skip to content

refactor: decompose _type_check_params, _convert_shapes, _set_color_source_vec#741

Merged
timtreis merged 3 commits into
mainfrom
refactor/issue-716-type-check-params
Jun 22, 2026
Merged

refactor: decompose _type_check_params, _convert_shapes, _set_color_source_vec#741
timtreis merged 3 commits into
mainfrom
refactor/issue-716-type-check-params

Conversation

@timtreis

@timtreis timtreis commented Jun 22, 2026

Copy link
Copy Markdown
Member

Closes #716. Decomposes the relocated mega-functions, one commit per function for bisectability.

Commits

  1. _type_check_params (_validate.py, 372 lines / CCN≈164) → 19 module-private _check_* helpers + a flat ordered orchestrator (CCN≈1). Behavior-preserving: call order (first-raised error) and all param_dict mutations identical. contour_px keeps its split type/range checks at their original positions; the interleaved cmap/palette/groups region stays one element_type-aware helper. Verified: 370-case old-vs-main differential, 0 mismatches; new test_type_check_params_preserves_validation_order.
  2. _convert_shapes (_geometry.py) → hoisted the stateless circle→hex/square/circle converters to module level and deduped the copy-pasted convex-hull into one _enclosing_circle. Verified: byte-identical geometry output across circles/polygons/multipolygons × circle/hex/visium_hex/square.
  3. _set_color_source_vec (_color.py, 236 lines / CCN≈48 → 171 / CCN≈29) → extracted _resolve_color_origins, _fetch_color_source_vector, _resolve_color_table (the categorical-mapping + output assembly stay inline). Verified: byte-identical (source_vector, color_vector, categorical) over 160 cases (element × color-column × palette × groups × render_type).

Not done (deliberately)

_get_collection_shape — the issue listed it (CCN 39), but #699 has since shrunk it to 65 lines / CCN≈17, below the decomposition bar. Left as-is.

Verification

Full non-visual suite 510 passed on each step. The two rendering-output functions (_convert_shapes, _set_color_source_vec) are additionally locked by the differential harnesses above; final visual sign-off is CI baselines.

@timtreis timtreis changed the title refactor(validate): decompose _type_check_params into per-parameter helpers (#716) refactor(validate): decompose _type_check_params into per-parameter helpers Jun 22, 2026
…elpers (#716)

Split the 372-line, CCN~164 _type_check_params into 19 module-private
_check_* helpers, each validating one parameter group in place; the function
is now a flat ordered sequence of calls. Behavior-preserving: the call order
(hence the first-raised error for any input) and all param_dict mutations are
identical. Verified by a 370-case old-vs-new differential (0 mismatches) and
the full non-visual suite (510 passed).

Notable: contour_px keeps two checks at their original positions (type before
color, range after outline) and _check_contour_px_range re-fetches contour_px
from param_dict; the interleaved cmap/palette/groups region stays one helper.

Adds a direct order-preservation test (color before contour_px range).
@timtreis timtreis force-pushed the refactor/issue-716-type-check-params branch from 1e2f8ab to fbfa9b4 Compare June 22, 2026 10:46
…#716)

Hoist the stateless circle->hexagon/square/circle converters to module level and
dedup the copy-pasted convex-hull enclosing-circle computation into a single
_enclosing_circle helper (was duplicated across the polygon and multipolygon
paths). _convert_shapes keeps only the closures that bind max_extent / the
warn_shape_size flag. Behavior-preserving: verified byte-identical geometry
output (old vs new) across circles/polygons/multipolygons x circle/hex/visium_hex/square.
@codecov-commenter

codecov-commenter commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.59%. Comparing base (e454700) to head (6bf751c).

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/_color.py 57.57% 10 Missing and 4 partials ⚠️
src/spatialdata_plot/pl/_geometry.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #741      +/-   ##
==========================================
+ Coverage   79.31%   79.59%   +0.27%     
==========================================
  Files          17       17              
  Lines        4603     4641      +38     
  Branches     1030     1029       -1     
==========================================
+ Hits         3651     3694      +43     
+ Misses        602      598       -4     
+ Partials      350      349       -1     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/_validate.py 70.67% <100.00%> (+2.10%) ⬆️
src/spatialdata_plot/pl/_geometry.py 79.53% <95.45%> (-0.65%) ⬇️
src/spatialdata_plot/pl/_color.py 69.76% <57.57%> (+0.45%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis timtreis changed the title refactor(validate): decompose _type_check_params into per-parameter helpers refactor: decompose _type_check_params, _convert_shapes, _set_color_source_vec (#716) Jun 22, 2026
…ource_vec (#716)

Pull the three self-contained decision blocks out of the 236-line color resolver:
_resolve_color_origins (locate + df/table shadowing + multi-origin error),
_fetch_color_source_vector (direct-read fast path vs whole-table join), and
_resolve_color_table (which table supplies .uns colors). _set_color_source_vec
drops 236->171 lines (CCN ~48->~29); the categorical-mapping and output assembly
stay inline. Behavior-preserving: verified byte-identical (source_vector,
color_vector, categorical) output over 160 cases (element x color-column x palette
x groups x render_type); full non-visual suite green (510 passed).
@timtreis timtreis force-pushed the refactor/issue-716-type-check-params branch from 2ef6a86 to 6bf751c Compare June 22, 2026 11:07
@timtreis timtreis changed the title refactor: decompose _type_check_params, _convert_shapes, _set_color_source_vec (#716) refactor: decompose _type_check_params, _convert_shapes, _set_color_source_vec Jun 22, 2026
@timtreis timtreis merged commit 50a6606 into main Jun 22, 2026
7 of 8 checks passed
@timtreis timtreis deleted the refactor/issue-716-type-check-params branch June 22, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: decompose the 4 relocated mega-functions (_type_check_params, _set_color_source_vec, _get_collection_shape, _convert_shapes)

2 participants