Skip to content

Improper conversion of Pandas-Arrow date to datetime fails #4171

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

Open
s-banach opened this issue Apr 20, 2023 · 1 comment
Open

Improper conversion of Pandas-Arrow date to datetime fails #4171

s-banach opened this issue Apr 20, 2023 · 1 comment
Labels
bug something broken P3 backlog

Comments

@s-banach
Copy link

s-banach commented Apr 20, 2023

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.

import datetime

import plotly.express as px
import polars as pl

df = pl.DataFrame(
    {
        "x": [datetime.date(2020, n, 1) for n in range(1, 13)],
        "y": [3 * n % 13 for n in range(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())
@s-banach s-banach changed the title Plot figure with Pandas Arrow date type as x-axis Improper conversion of Pandas-Arrow date to datetime fails Apr 20, 2023
@gvwilson gvwilson self-assigned this Jul 11, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added P3 backlog bug something broken labels Aug 12, 2024
@MarcoGorelli
Copy link
Contributor

@emilykl I think this can be closed now, as per discussion in #4836, if I run this code now with the latest plotly build then the figure displays correctly

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

No branches or pull requests

3 participants