Deduplicate shared logic between _render_shapes and _render_points#551
Draft
Deduplicate shared logic between _render_shapes and _render_points#551
Conversation
2a85988 to
1d8ac75
Compare
Extract 8 helper functions from the near-identical datashader rendering paths in _render_shapes() and _render_points(): - _apply_datashader_norm: norm vmin/vmax edge-case handling - _build_datashader_colorbar_mappable: ScalarMappable construction - _datashader_aggregate: categorical/continuous/no-color aggregation - _datashader_shade_continuous: continuous color mapping + spread + NaN - _datashader_shade_categorical: categorical/no-color color mapping - _render_datashader_result: RGBA image rendering + NaN overlay - _make_palette: ListedColormap construction - _decorate_render: legend/colorbar/scalebar decoration Also refactor the show() dispatch loop in basic.py from 4 if/elif branches to a table-driven pattern. No public API changes. No behavioral changes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1d8ac75 to
db51af4
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #551 +/- ##
==========================================
- Coverage 73.68% 73.66% -0.03%
==========================================
Files 9 10 +1
Lines 2744 2738 -6
Branches 651 637 -14
==========================================
- Hits 2022 2017 -5
Misses 447 447
+ Partials 275 274 -1
🚀 New features to boost your workflow:
|
- _render_ds_outlines: consolidates the 40-line outline aggregation + shading + rendering block (outer + inner) into a single loop - _build_color_key: extracts the identical color key construction from both shapes and points datashader paths The shapes and points datashader pipelines now read nearly identically, differing only in parameter values. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Functions: - _datashader_aggregate -> _ds_aggregate (consistent prefix) - _datashader_shade_continuous -> _ds_shade_continuous - _datashader_shade_categorical -> _ds_shade_categorical - _apply_datashader_norm -> _apply_ds_norm - _build_datashader_colorbar_mappable -> _build_ds_colorbar - _render_datashader_result -> _render_ds_image - _decorate_render -> _add_legend_and_colorbar Variables: - aggregate_with_reduction -> reduction_bounds - continuous_nan_agg -> nan_agg - continuous_nan_shaded -> nan_shaded - ds_result -> shaded - ds_span -> color_span Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All datashader-specific aggregation, shading, and rendering helpers now live in pl/_datashader.py. render.py imports them and focuses on the element-type-specific orchestration logic. Moved: - _ds_aggregate, _apply_ds_norm, _build_color_key - _ds_shade_continuous, _ds_shade_categorical - _render_ds_image, _render_ds_outlines, _build_ds_colorbar - _coerce_categorical_source, _build_datashader_color_key - _inject_ds_nan_sentinel, _DS_NAN_CATEGORY, _DsReduction Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…isions" This reverts commit 6985eff.
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.
Summary
_render_shapes()(519 lines) and_render_points()(437 lines), eliminating ~240 lines of duplicated codeshow()dispatch loop from 4 if/elif branches to a table-driven patternMotivation
_render_shapesand_render_pointsfollowed the same structure with large blocks of near-identical code (norm handling, aggregation, color mapping, NaN shading, image rendering, colorbar construction, decoration). Every bug fix or feature had to be manually replicated in both functions, and they were already drifting (different default reductions, subtly different categorical detection).Extracted helpers
_apply_datashader_norm_datashader_aggregate_datashader_shade_continuous_datashader_shade_categorical_render_datashader_result_build_datashader_colorbar_mappable_make_palette_decorate_renderTest plan
🤖 Generated with Claude Code