Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor trace-specific color handling in apply_default_cascade
- Make constructor parameter required (was optional with None default)
- Refactor trace-specific color extraction to only assign when colors are found
- Improve code clarity by checking for non-empty color list before assignment
  • Loading branch information
antonymilne committed Dec 4, 2025
commit 675c668fcfefab9b4b3b1a0ed81a36ac22e807d4
8 changes: 6 additions & 2 deletions plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def one_group(x):
return ""


def apply_default_cascade(args, constructor=None):
def apply_default_cascade(args, constructor):
# first we apply px.defaults to unspecified args

for param in defaults.__slots__:
Expand Down Expand Up @@ -1047,12 +1047,16 @@ def apply_default_cascade(args, constructor=None):
else:
trace_type = constructor().type
if trace_data_list := getattr(args["template"].data, trace_type, None):
args["color_discrete_sequence"] = [
trace_specific_colors = [
trace_data.marker.color
for trace_data in trace_data_list
if hasattr(trace_data, "marker")
and hasattr(trace_data.marker, "color")
]
# If template contains at least one color for this trace type, assign to color_discrete_sequence
if any(trace_specific_colors):
args["color_discrete_sequence"] = trace_specific_colors

if not args["color_discrete_sequence"] or not any(
args["color_discrete_sequence"]
):
Expand Down