Skip to content

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

Description

@s-banach

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())

Activity

  1. changed the title [-]Plot figure with Pandas Arrow date type as x-axis[/-] [+]Improper conversion of Pandas-Arrow date to datetime fails[/+] on Apr 20, 2023
  2. self-assigned this
    on Jul 11, 2024
  3. removed their assignment
    on Aug 2, 2024
  4. MarcoGorelli commented on Nov 26, 2024

    @MarcoGorelli
    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

  5. emilykl commented on Aug 30, 2026

    @emilykl
    Contributor

    @MarcoGorelli @s-banach Just following up on this one, yes this can be closed! Resolved by #4790, first released in plotly.py v6.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions