feat: colors parameter for easy color assignment#24
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds a unified Changes
Sequence DiagramsequenceDiagram
participant User as User Code
participant Accessor as Accessor Method
participant Plotting as Plotting Function
participant Resolver as resolve_colors()
participant PX as Plotly Express
User->>Accessor: call accessor(..., colors=...)
Accessor->>Plotting: call plotting(..., colors=..., **px_kwargs)
Plotting->>Resolver: resolve_colors(colors, px_kwargs)
Resolver->>Resolver: validate type & detect scale (qualitative/continuous)
Resolver->>Resolver: map to px kwarg(s) (color_discrete_sequence / color_continuous_scale / color_discrete_map)
Resolver-->>Plotting: return modified px_kwargs
Plotting->>PX: px.* with resolved px_kwargs
PX-->>Plotting: Figure
Plotting-->>Accessor: Figure
Accessor-->>User: Figure
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tests/test_accessor.py`:
- Around line 462-476: The test
test_colors_ignored_with_warning_when_px_kwargs_present is brittle because it
asserts len(w) == 1; instead, change the assertion to verify that the expected
warning about "colors" being "ignored" is present in the captured warnings
(e.g., use any("colors" in str(m.message).lower() and "ignored" in
str(m.message).lower() for m in w) or similar) and remove the strict count check
so unrelated warnings won't break the test; keep the subsequent assertion that
fig.data[0].line.color == "orange" to ensure px kwargs take precedence.
Summary
Add a unified
colorsparameter to all plotting functions for easier color customization. Instead of remembering whether to usecolor_discrete_sequence,color_continuous_scale, orcolor_discrete_map, users can now simply usecolorsand the library automatically maps it to the correct Plotly parameter based on the input type.Type-based mapping
colors="D3"color_discrete_sequencecolors="Viridis"color_continuous_scalecolors=["red", "blue"]color_discrete_sequencecolors={"A": "red"}color_discrete_mapExamples
Precedence
Explicit
color_*kwargs inpx_kwargstake precedence overcolors. A warning is issued whencolorsis ignored due to explicit kwargs.Changes
Colorstype alias andresolve_colors()helper incommon.pycolorsparameter to all 8 plotting functions inplotting.pycolorsparameter to all 16 accessor methods inaccessor.pyColorstype from packagedocs/examples/kwargs.ipynbTest plan
colorsparameter (12 tests)colorsconflicts with explicitcolor_*kwargs🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
colorsparameter across all plotting functions (line, bar, area, scatter, imshow, pie, and others), supporting qualitative color palettes, color lists, color mappings, and continuous scales for flexible visualization customization.Tests
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.