The Issue
Consider this branch of code:
It attempts to call v.dt.to_pydatetime() on a Series with any kind of date or time dtype.
This isn't correct, because a date dtype is different than a datetime dtype, see the comment from pandas maintainer @mroeschke on this issue: pandas-dev/pandas#52812. In other words, this is unsupported by pandas, and will continue to raise an error in the future.
You should probably just use v.to_numpy() instead.
Reproducing Code
The following code results in the error AttributeError: 'pyarrow.lib.DataType' object has no attribute 'unit', as a result of the above bug.
importdatetimeimportplotly.expressaspximportpolarsaspldf=pl.DataFrame(
{
"x": [datetime.date(2020, n, 1) forninrange(1, 13)],
"y": [3*n%13forninrange(1, 13)],
}
).to_pandas(use_pyarrow_extension_array=True)
fig=px.bar(data_frame=df, x="x", y="y")
fig.show()Note that the following code works, by properly calling .to_numpy() and letting pandas figure out how to handle it:
fig=px.bar(x=df["x"].to_numpy(), y=df["y"].to_numpy())
The Issue
Consider this branch of code:
plotly.py/packages/python/plotly/_plotly_utils/basevalidators.py
Line 103 in 956ab2c
It attempts to call
v.dt.to_pydatetime()on a Series with any kind of date or time dtype.This isn't correct, because a
datedtype is different than adatetimedtype, see the comment from pandas maintainer @mroeschke on this issue: pandas-dev/pandas#52812. In other words, this is unsupported by pandas, and will continue to raise an error in the future.You should probably just use
v.to_numpy()instead.Reproducing Code
The following code results in the error
AttributeError: 'pyarrow.lib.DataType' object has no attribute 'unit', as a result of the above bug.Note that the following code works, by properly calling
.to_numpy()and letting pandas figure out how to handle it: