fix: handle scalar input with bytes=True in Colormap.__call__ - #154
Open
abhi-0203 wants to merge 1 commit into
Open
fix: handle scalar input with bytes=True in Colormap.__call__#154abhi-0203 wants to merge 1 commit into
abhi-0203 wants to merge 1 commit into
Conversation
When bytes=True and a scalar input is provided, the LUT is converted to uint8 before indexing. The resulting 4-element uint8 array was passed directly to Color(), which expects float values in [0, 1]. This raised ValueError: 'Invalid color array: array([32, 144, 140, 255], dtype=uint8)'. Fix: when bytes=True and the input is scalar, normalize the uint8 RGBA values back to [0, 1] float range before constructing Color(). The quantization to 8-bit is preserved in the rounding. Closes pyapp-kit#153
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (80.00%) is below the target coverage (85.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #154 +/- ##
==========================================
- Coverage 95.71% 95.67% -0.04%
==========================================
Files 168 168
Lines 2192 2196 +4
==========================================
+ Hits 2098 2101 +3
- Misses 94 95 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Fixes
Colormap.__call__raisingValueErrorwhen called with a scalar input andbytes=True.Problem
When
bytes=True, the LUT is converted touint8before indexing. For scalar input, the result is a 4-elementuint8array (e.g.[32, 144, 140, 255]), which is then passed toColor(). ButColor()(viaparse_rgba) only accepts:A
uint8array of length 4 doesn't match either condition, raisingValueError: Invalid color array.Fix
When
bytes=Trueand the input is scalar, normalize theuint8RGBA values back to[0, 1]float range before constructingColor(). The quantization to 8-bit is preserved —Color(rgba / 255)gives#20908Cvs#21918Cin float mode, showing thebytes=Trueeffect.Test results
Closes #153