Skip to content
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

Using 'date' type for scatter xaxis fails when coordinates stored in Numpy array #1927

Closed
jordanweaver opened this issue Nov 25, 2019 · 4 comments

Comments

@jordanweaver
Copy link

jordanweaver commented Nov 25, 2019

It's possible (nay, likely) that I'm misunderstanding something but the docs indicate that Numpy arrays containing timestamps should be allowed. Yet, I'm currently having to cast this into a Pandas Series for it to work:

# plotly date axis bug?
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objects as go

import numpy as np
import pandas as pd


app = dash.Dash(__name__)

timestamps = np.array(
    [
        '2017-05-24T23:00:21',
        '2017-05-24T23:00:23',
        '2017-05-24T23:00:25',
        '2017-05-24T23:00:27',
        '2017-05-24T23:00:29'
    ],
    dtype='datetime64[ns]'
)
fake_data = np.arange(len(timestamps))

fig_working = go.Figure().add_scatter(
    x=pd.Series(timestamps),
    y=fake_data
).update_layout(xaxis_type='date')


fig_working_not_so_much = go.Figure().add_scatter(
    x=timestamps,
    y=fake_data
).update_layout(xaxis_type='date')


app.layout = html.Div(
    [
        html.H1("Working with a pandas.Series:"),
        dcc.Graph(figure=fig_working),

        html.H1("Same data in a numpy.array:"),
        dcc.Graph(figure=fig_working_not_so_much),

        html.H1("😿")
    ]
)


if __name__ == '__main__':
    app.run_server(debug=True)

This yields:

image

@jordanweaver jordanweaver changed the title Using 'date' type for scatter xaxis fails when for coordinates stored in Numpy array Using 'date' type for scatter xaxis fails when coordinates stored in Numpy array Nov 25, 2019
@eceforge
Copy link

So I'm moderately sure this has to do with the fact that pandas stores its datatime64[ns] internally as 'int64' where as numpy stores it as 'uint64'. It's supposed to be number of nanoseconds since epoch, so I can't imagine there would be a need for negative counts, but I don't know enough about the intent pandas had there.

@nicolaskruchten
Copy link
Contributor

@jonmmease maybe let's take a look at this in the context of the #2955 thing?

@nicolaskruchten
Copy link
Contributor

@jonmmease was this fixed by #3022 actually?

@nicolaskruchten
Copy link
Contributor

I'm not sure when this was fixed, but it no longer happens on master, and so at the very least will be fixed in 5.0 :)

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

No branches or pull requests

3 participants