Skip to content

fix: name2color() colororder reordering returns list, not ndarray - #93

Merged
petercorke merged 1 commit into
mainfrom
fix/name2color-colororder-ndarray
Aug 16, 2026
Merged

fix: name2color() colororder reordering returns list, not ndarray#93
petercorke merged 1 commit into
mainfrom
fix/name2color-colororder-ndarray

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

  • BaseFeature2D.draw2(image, color='y') crashes with AttributeError: 'list' object has no attribute 'flat' whenever image has a real colororder (e.g. from .colorize()).
  • Root cause: name2color()'s colororder reordering (color = [color[colororder[c]] for c in colorspace]) uses a list comprehension, which silently converts the ndarray return value into a plain Python list. Every other caller of name2color() (and its 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 via a regex name), so this was an undocumented third return shape introduced by accident.
  • draw2() is the only caller that ever passes colororder= (checked all call sites), and it does color_ndarray.flat[0] etc. on the result.
  • Fix: fancy-index (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) -- asserts ndarray return type and correct reordering for both RGB and BGR colororders
  • tests/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)
  • Full test suite: no regressions
  • Manually verified against RVC3-python's chap14.ipynb notebook (visual odometry section, features.draw2(image, color='y'))

🤖 Generated with Claude Code

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

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
petercorke force-pushed the fix/name2color-colororder-ndarray branch from fe864ff to c90e6fb Compare August 16, 2026 02:17
@petercorke
petercorke merged commit b8fdf03 into main Aug 16, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant