plotly / plotly/plotly.py

Allow arbitrary `Mapping` types when setting properties, rather than only `dict`

Open
#4,212 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

Currently, it seems that only dict is allowed when setting properties. It would be better if an arbitrary Mapping type were allowed, since that grants the user the flexibility to control properties with alternative data structures such as a ChainMap.

As far as I can tell, this could be done just by changing the validate_coerce() logic to check isinstance(v, Mapping) instead of isinstance(v, dict), e.g. on this line.

Example

This raises a ValueError:

from collections import ChainMap

import plotly.graph_objects as go


layout = ChainMap(
    dict(width=1000),
    dict(width=500, height=500),
)
go.Figure(layout=layout)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/python/plotly/_plotly_utils/basevalidators.py at the validate_coerce() logic referenced in the issue. Check how the Figure(layout=ChainMap(...)) example is validated, then verify that arbitrary Mapping inputs are accepted without changing existing dict behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.