fix: name2color() colororder reordering returns list, not ndarray - #93
Merged
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
The colororder-reordering branch used a list comprehension (color = [color[colororder[c]] for c in colorspace]), which silently converts the ndarray return value into a plain Python list. Every other caller of name2color() (and the function's own docstring :rtype:) expects an ndarray for the numeric-lookup case -- the documented list[str] return is a completely different mode (wildcard color-name search), so this was an undocumented third return shape introduced by accident. draw2() is the only caller that passes colororder=, and it calls color_ndarray.flat[...] on the result, which crashed with AttributeError: 'list' object has no attribute 'flat' whenever an image with a real colororder (e.g. from .colorize()) was passed in. Fixed with fancy indexing instead of a list comprehension, which preserves the ndarray type. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
petercorke
force-pushed
the
fix/name2color-colororder-ndarray
branch
from
August 16, 2026 02:17
fe864ff to
c90e6fb
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.
Summary
BaseFeature2D.draw2(image, color='y')crashes withAttributeError: 'list' object has no attribute 'flat'wheneverimagehas a realcolororder(e.g. from.colorize()).name2color()'scolororderreordering (color = [color[colororder[c]] for c in colorspace]) uses a list comprehension, which silently converts the ndarray return value into a plain Pythonlist. Every other caller ofname2color()(and its own docstring:rtype:) expects an ndarray for the numeric-lookup case -- the documentedlist[str]return is a completely different mode (wildcard color-name search via a regexname), so this was an undocumented third return shape introduced by accident.draw2()is the only caller that ever passescolororder=(checked all call sites), and it doescolor_ndarray.flat[0]etc. on the result.color[[colororder[c] for c in colorspace]]) instead of a list comprehension, preserving the ndarray type -- matches what every other caller already assumes.Test plan
tests/base/test_base_color.py::TestColor::test_name2color_colororder(new) -- assertsndarrayreturn type and correct reordering for both RGB and BGR colororderstests/test_image_point_features.py::TestImagePointFeatures::test_draw2(new) -- exercises the actual originally-failing call path end-to-end (ORB features drawn onto a colorized image)features.draw2(image, color='y'))🤖 Generated with Claude Code