Skip to content

px.timeline loses type of x_end values #2934

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

Closed
eyak opened this issue Nov 25, 2020 · 4 comments · Fixed by #3018
Closed

px.timeline loses type of x_end values #2934

eyak opened this issue Nov 25, 2020 · 4 comments · Fixed by #3018
Milestone

Comments

@eyak
Copy link

eyak commented Nov 25, 2020

While px.timeline uses x_end values as expected and creates the proper graph,
trying to display the x_end values either as text or as hoverdata fails

image

import pandas as pd
import plotly.express as px
import datetime

data = pd.DataFrame([{
    'Start Date': datetime.datetime(2020, 1, 1),
    'End Date': datetime.datetime(2020, 2, 1),
    'Test Date': datetime.datetime(2020, 2, 1),
    'y': 100
},
    {
    'Start Date': datetime.datetime(2020, 1, 10),
    'End Date': datetime.datetime(2020, 2, 10),
    'Test Date': datetime.datetime(2020, 2, 10),
    'y': 90
}])

hover_data = {
    'Start Date': '|%x',
    'End Date': '|%x',
    'Test Date': '|%x'
}

fig = px.timeline(data, x_start="Start Date", x_end="End Date",
                  y="y", text='End Date', hover_data=hover_data)
fig.show()
@eyak
Copy link
Author

eyak commented Nov 29, 2020

Here's what happens inside process_dataframe_timeline:

# note that we are not adding any columns to the data frame here, so no risk of overwrite
args["data_frame"][args["x_end"]] = (x_end - x_start).astype("timedelta64[ms]")

x_end is overwritten internally, so downstream references to x_end result in the 'massaged' data instead of the original data

@nicolaskruchten nicolaskruchten added this to the v4.x milestone Dec 17, 2020
@nicolaskruchten
Copy link
Contributor

Related to/duplicate of #2518 ... it seems like at the moment, using text="End Date" or having "End Date" in hover_data causes type issues.

@nicolaskruchten nicolaskruchten changed the title px.timeline looses type of x_end values px.timeline loses type of x_end values Jan 12, 2021
@nicolaskruchten
Copy link
Contributor

@nicolaskruchten
Copy link
Contributor

OK, so I have a fix for the hover_data case, but I won't have a fix for the text case for a while, so I'm breaking that off into a separate issue here: #3019

For now, the workaround for text is to pass in a separate column:

import plotly.express as px
import pandas as pd

df = pd.DataFrame([
    dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Resource="Alex"),
    dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15', Resource="Alex"),
    dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30', Resource="Max")
])
fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task", text=df["Finish"].copy())
fig.update_yaxes(autorange="reversed")
fig.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants