perf(color): map categorical shapes colour by code, not per-row hex parse#737
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #737 +/- ##
==========================================
+ Coverage 79.26% 79.28% +0.02%
==========================================
Files 17 17
Lines 4596 4601 +5
Branches 1028 1029 +1
==========================================
+ Hits 3643 3648 +5
Misses 603 603
Partials 350 350
🚀 New features to boost your workflow:
|
…arse ColorSpec.to_rgba (the matplotlib shapes fill+outline mapping) parsed every row via to_rgba_array(list(color_vector)). For a categorical color_vector (K distinct hex over N rows) this is O(N) string parsing for O(K) colours. Map the K categories once and gather by code (codes >= 0: resolution fills NaN with an na_color category); object vectors (align_to_length pad, uniform na) use pd.factorize(sort=False) on the distinct colours. Byte-identical to the per-row parse (verified main-vs-branch on categorical fill/outline/groups, max|diff|=0), ~56x on the categorical path, ~16x on the object path. Continuous (source_vector is None) is untouched; labels (map_array codes) and points (#731) already use the compact form.
3c8c1df to
f486614
Compare
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
ColorSpec.to_rgba— the matplotlib shapes fill + outline colour mapping — parses every row viato_rgba_array(list(color_vector)). For a categoricalcolor_vector(K distinct hex strings over N rows) that is O(N) string parsing for O(K) actual colours.Fix
color_vector: parse the K categories once, gather by.codes(codes ≥ 0 — resolution fills NaN with an explicitna_colorcategory,_color.py:682–685).color_vector(align_to_lengthpad / uniform na):pd.factorize(sort=False)on the distinct colours, then gather. (np.uniquewould sort the hex strings and is slower than the baseline at scale — deliberately avoided.)Byte-identical
Verified main-vs-branch on real renders — categorical fill, categorical+outline, categorical+groups, none — max|diff| = 0. Unit test
TestColorSpecToRgbalocksto_rgbaagainst the per-rowto_rgba_array(list(...))across all 5color_vectorvariants (clean / na-category / filtered / none-uniform / object-after-align).Scope & impact
source_vector is None) untouched; labels (map_arraycodes) and points (perf(render_points): keep categorical colour as codes+palette (memory at scale) #731) already use the compact form; datashader shapes don't callto_rgba.