Repository navigation
mixed-face-colors patch - #3866
Merged
Merged
Conversation
|
Performance benchmarks:
|
EwoutH
pushed a commit
that referenced
this pull request
Oct 28, 2026
* mixed-face-colors patch * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update assertion for uniform result shape --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tom Pike <[email protected]> (cherry picked from commit f376606)
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.
Pre-PR Checklist
Summary
Extends the object-array fallback added in #3856 to face colors (
c), so mixing plain color-name strings and RGBA tuples across agents doesn't crashcollect_agent_data.Bug
Raised by @Dilraj07 during review of #3856:
_to_numpy_argument_arrayhandles mixed color representations foredgecolors, butc(face color) can hit the exact same failure.np.asarray(["blue", (1.0, 0.0, 0.0, 1.0)])raisesValueError: setting an array element with a sequence...for the same reason the originaledgecolorsbug did — NumPy can't coerce a plain string next to a 4-tuple into one array.This is a pre-existing bug, not introduced by #3856 — the same call would have failed on
mainbefore that PR too. Filed as a separate follow-up per discussion on #3856 to keep that PR scoped to #2691.Fix
np.asarray/exceptValueError/manual-object-array logic out of theedgecolorsbranch into a small_coerce_or_object_array()helper.c, so mixed face colors fall back to a 1D object array the same way mixed edgecolors do.np.asarrayalready turns those into a valid(N, 4)/(N, 3)array, which is exactly what Matplotlib expects, so only genuinely mixed representations take the fallback path.MatplotlibBackendneeds no changes: it already imports_to_numpy_argument_arrayfrommpl_space_drawing.py, so it picks up the fix automatically.Testing
test_to_numpy_argument_array_mixed_face_colors— unit test confirming a mixed["blue", (1.0, 0.0, 0.0, 1.0)]list round-trips correctly, and a uniform RGBA-tuple list still produces a proper(N, 4)array rather than being forced into an object array.test_draw_network_with_mixed_face_colors— end-to-end regression test throughdraw_networkwith agents split between a plain color name and an RGBA tuple.MatplotlibBackend.collect_agent_datahandles the same mixed-color case correctly with zero changes to that file.Additional Notes
Scoped to matplotlib visualization style collection only — no public API, dependency, schema, or CI changes. Builds directly on the
_to_numpy_argument_arrayhelper introduced in #3856; please merge that first if it hasn't landed yet, since this branches from it.