Skip to content

Commit 2f9a0a1

Browse files
Merge pull request #3018 from plotly/hoverdatareuse
reuse x/y/z/base in hover data
2 parents b7a41eb + f12c7bf commit 2f9a0a1

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55

6+
## [4.14.3] - UNRELEASED
7+
8+
### Fixed
9+
10+
- `px.timeline()` now allows `hover_data` formatting of start and end times [3018](https://github.com/plotly/plotly.py/pull/3018)
11+
12+
613
## [4.14.2] - 2021-01-11
714

815
### Updated

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,10 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
375375
trace_patch[error_xy] = {}
376376
trace_patch[error_xy][arr] = trace_data[attr_value]
377377
elif attr_name == "custom_data":
378-
# here we store a data frame in customdata, and it's serialized
379-
# as a list of row lists, which is what we want
380-
trace_patch["customdata"] = trace_data[attr_value]
378+
if len(attr_value) > 0:
379+
# here we store a data frame in customdata, and it's serialized
380+
# as a list of row lists, which is what we want
381+
trace_patch["customdata"] = trace_data[attr_value]
381382
elif attr_name == "hover_name":
382383
if trace_spec.constructor not in [
383384
go.Histogram,
@@ -398,6 +399,13 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
398399
for col in attr_value:
399400
if hover_is_dict and not attr_value[col]:
400401
continue
402+
if col in [
403+
args.get("x", None),
404+
args.get("y", None),
405+
args.get("z", None),
406+
args.get("base", None),
407+
]:
408+
continue
401409
try:
402410
position = args["custom_data"].index(col)
403411
except (ValueError, AttributeError, KeyError):
@@ -408,9 +416,10 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
408416
position
409417
)
410418

411-
# here we store a data frame in customdata, and it's serialized
412-
# as a list of row lists, which is what we want
413-
trace_patch["customdata"] = trace_data[customdata_cols]
419+
if len(customdata_cols) > 0:
420+
# here we store a data frame in customdata, and it's serialized
421+
# as a list of row lists, which is what we want
422+
trace_patch["customdata"] = trace_data[customdata_cols]
414423
elif attr_name == "color":
415424
if trace_spec.constructor in [go.Choropleth, go.Choroplethmapbox]:
416425
trace_patch["z"] = trace_data[attr_value]

Diff for: packages/python/plotly/plotly/tests/test_core/test_px/test_px_input.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ def test_pass_df_columns():
309309
marginal="rug",
310310
hover_data=tips.columns,
311311
)
312-
assert fig.data[1].hovertemplate.count("customdata") == len(tips.columns)
312+
# the "- 2" is because we re-use x and y in the hovertemplate where possible
313+
assert fig.data[1].hovertemplate.count("customdata") == len(tips.columns) - 2
313314
tips_copy = px.data.tips()
314315
assert tips_copy.columns.equals(tips.columns)
315316

0 commit comments

Comments
 (0)