-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Allowing hover_data and custom_data to pass string of column name instead of requiring a list. #4083
Allowing hover_data and custom_data to pass string of column name instead of requiring a list. #4083
Conversation
Thanks very much for this PR! I agree that the current behaviour is annoying enough that we should change it, and just accepting bare strings should work. I'll add some thoughts in the PR comments. |
The build-doc is failing on make html. I made some real small changes to the documentation but just within strings. Can't tell if I've got some hard to spot or silly mistake or if this is just being funky. 🤔 |
|
Thanks very much for this PR! |
Happy to contribute and I appreciate your help in the process! Out of curiosity, what's the general cadence of releases or expected next release date? Not in any rush but will be excited to see my minor contribution in the wild 😎 EDIT: Actually looking at the changelog gives me a sense. Thanks again! |
We generally do minor releases timed with Plotly.js minor releases, or sooner if there are a batch of Python-driven features waiting for release. I'm not sure when the next Plotly.js minor is expected but likely within a few weeks. |
Howdy y'all!
Quick background
I often get tripped up when using the
hover_data
argument since nearly all arguments can be a single string of a column name except it (andcustom_data
). To make matters a bit worse the error message is quite confusing, example below.This produces the following error
which is pretty misleading since I did pass 'day'!
This has been brought up in the following issues:
custom_data
#2177Instead of making the error message more clear, I think we should just allow a single string of a column name to be consistent with nearly all other args.
Source of problem
It appears the source of the problem is
hover_data
(andcustom_data
) are both inarray_attrables
and get cast as a list usinglist(arg)
. And ifarg
is a string like'my_col'
this turns it into['m', 'y', '_', 'c', 'o', 'l']
which is undesirable.Simple Solution
Thus my simple band-aid solution is checking if the field is in
["custom_data", "hover_data"]
and ifargs[field] in args["data_frame"].columns
then we instead turn it into a list simply doingargs[field] = [args[field]]
. This suffices as shown in the screenshot below.Other ideas?
I'm open to ideas if folks prefer we do it in a different way (particularly the hardcoded list might be good define explicitly up top with an informative name) but I wanted to get a simple enough solution proposed that works.
I've also update the docs in this PR to reflect that this change would allow you to pass a string to both
hover_data
andcustom_data
-- I don't know if it's preferable or not for these to be in the same PR.Happy to get any other feedback as well as this is my first attempt at an open source contribution. 😎
Thanks,
Luke Feilberg
Documentation PR
doc/README.md
filedoc-prod
branch OR it targets themaster
branchpx
example if at all possibleplotly.graph_objects as go
/plotly.express as px
/plotly.io as pio
df
fig = <something>
call is high up in each new/modified example (eitherpx.<something>
ormake_subplots
orgo.Figure
)fig.add_*
andfig.update_*
rather thango.Figure(data=..., layout=...)
in every new/modified examplefig.add_shape
andfig.update_xaxes
are used instead of bigfig.update_layout
calls in every new/modified examplefig.show()
is at the end of each new/modified exampleplotly.plot()
andplotly.iplot()
are not used in any new/modified exampleCode PR
plotly.graph_objects
, my modifications concern thecodegen
files and not generated files.modified existing tests.
new tutorial notebook (please see the doc checklist as well).