Skip to content

Allowing hover_data and custom_data to pass string of column name instead of requiring a list. #4083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,11 +1295,17 @@ def build_dataframe(args, constructor):
# make copies of all the fields via dict() and list()
for field in args:
if field in array_attrables and args[field] is not None:
args[field] = (
dict(args[field])
if isinstance(args[field], dict)
else list(args[field])
)
if isinstance(args[field], dict):
args[field] = dict(args[field])
elif (
field in ["custom_data", "hover_data"]
and isinstance(args[field], str)
and "data_frame" in args.keys()
and args[field] in args["data_frame"].columns
):
args[field] = [args[field]]
else:
list(args[field])

# Cast data_frame argument to DataFrame (it could be a numpy array, dict etc.)
df_provided = args["data_frame"] is not None
Expand Down
8 changes: 4 additions & 4 deletions packages/python/plotly/plotly/express/_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@
"Values from this column or array_like appear in bold in the hover tooltip.",
],
hover_data=[
"list of str or int, or Series or array-like, or dict",
"Either a list of names of columns in `data_frame`, or pandas Series,",
"str, or list of str or int, or Series or array-like, or dict",
"Either a name or list of names of columns in `data_frame`, or pandas Series,",
"or array_like objects",
"or a dict with column names as keys, with values True (for default formatting)",
"False (in order to remove this column from hover information),",
Expand All @@ -211,8 +211,8 @@
"Values from these columns appear as extra data in the hover tooltip.",
],
custom_data=[
colref_list_type,
colref_list_desc,
"str, or list of str or int, or Series or array-like",
"Either name or list of names of columns in `data_frame`, or pandas Series, or array_like objects",
"Values from these columns are extra data, to be used in widgets or Dash callbacks for example. This data is not user-visible but is included in events emitted by the figure (lasso selection etc.)",
],
text=[
Expand Down