Skip to content

Commit 8c1c992

Browse files
committed
Allowing hover_data and custom_data to pass string of column name instead of list
1 parent 92ce5bc commit 8c1c992

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Diff for: packages/python/plotly/plotly/express/_core.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1295,11 +1295,17 @@ def build_dataframe(args, constructor):
12951295
# make copies of all the fields via dict() and list()
12961296
for field in args:
12971297
if field in array_attrables and args[field] is not None:
1298-
args[field] = (
1299-
dict(args[field])
1300-
if isinstance(args[field], dict)
1301-
else list(args[field])
1302-
)
1298+
if isinstance(args[field], dict):
1299+
args[field] = dict(args[field])
1300+
elif (
1301+
field in ["custom_data", "hover_data"]
1302+
and isinstance(args[field], str)
1303+
and "data_frame" in args.keys()
1304+
and args[field] in args["data_frame"].columns
1305+
):
1306+
args[field] = [args[field]]
1307+
else:
1308+
list(args[field])
13031309

13041310
# Cast data_frame argument to DataFrame (it could be a numpy array, dict etc.)
13051311
df_provided = args["data_frame"] is not None

Diff for: packages/python/plotly/plotly/express/_doc.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@
199199
"Values from this column or array_like appear in bold in the hover tooltip.",
200200
],
201201
hover_data=[
202-
"list of str or int, or Series or array-like, or dict",
203-
"Either a list of names of columns in `data_frame`, or pandas Series,",
202+
"str, or list of str or int, or Series or array-like, or dict",
203+
"Either a name or list of names of columns in `data_frame`, or pandas Series,",
204204
"or array_like objects",
205205
"or a dict with column names as keys, with values True (for default formatting)",
206206
"False (in order to remove this column from hover information),",
@@ -211,8 +211,8 @@
211211
"Values from these columns appear as extra data in the hover tooltip.",
212212
],
213213
custom_data=[
214-
colref_list_type,
215-
colref_list_desc,
214+
"str, or list of str or int, or Series or array-like",
215+
"Either name or list of names of columns in `data_frame`, or pandas Series, or array_like objects",
216216
"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.)",
217217
],
218218
text=[

0 commit comments

Comments
 (0)