Closed johnmccain closed 5 years ago
Would it be better to submit this issue under the plotly.py repository instead?
I have found the cause of the issue, in _core.py:847
Pandas .unique()
method returns a NumPy array, and as given in the examples section, it will convert a pandas.Timestamp
to a numpy.datetime64
.
>>> pd.Series([pd.Timestamp('2016-01-01') for _ in range(3)]).unique()
array(['2016-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
The uniques
list defined at _core.py:847 uses the .unique()
method, converting the series of pandas.Timestamp
into an array of numpy.datetime64
uniques = args["data_frame"][col].unique()
This distinction is relevant on line 857:
group_names = sorted(
group_names,
key=lambda g: orders[col].index(g[i]) if g[i] in orders[col] else -1
)
Which causes the ValueError when .index()
does not find a matching element due to this behavior of pandas.Timestamp and numpy.datetime64 seen here:
>>> pandas.Timestamp('2018-01-01 00:00:00') in [numpy.datetime64('2018-01-01T00:00:00.000000000')]
True
>>> [numpy.datetime64('2018-01-01T00:00:00.000000000')].index(pandas.Timestamp('2018-01-01 00:00:00'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Timestamp('2018-01-01 00:00:00') is not in list
Seeing as the faulty code is in the plotly.py repository, I am closing this issue and have reopened another there #1737
Attempting to animate a plot using a pandas Timestamp column results in an exception.
Using Python 3.6.8, plotly_express==0.4.1, plotly==4.1.0
Code to replicate:
Exception & stack trace: