Skip to content

Regression in kaleido 1.3.0 when saving plot with markers #458

Description

@StageTired

Observe the simple reproducible example at the end of the post . It works just fine when running it with

uv run --with pandas==2.3.3 --with numpy==2.4.4 --with plotly==6.7.0 --with kaleido==1.2.0 generate_plot_png.py

When I run the same script but with kaleido==1.3.0, it raises an exception.

TypeError: Type is not JSON serializable: Timestamp

Command:

uv run --with pandas==2.3.3 --with numpy==2.4.4 --with plotly==6.7.0 --with kaleido==1.3.0 generate_plot_png.py

Code:

import numpy as np
import pandas as pd
import plotly.graph_objects as go


def generate_dataframe() -> pd.DataFrame:
    rng = np.random.default_rng(42)
    index = pd.bdate_range("2026-01-30", "2026-06-03")

    data = {
        "col_1": np.round(rng.uniform(10.0, 30.0, len(index))),
        "col_2": np.round(rng.uniform(1.0, 30.0, len(index))),
        "col_3": np.round(rng.uniform(20.0, 50.0, len(index))),
        "col_4": np.round(rng.uniform(4.0, 100.0, len(index))),
        "col_5": np.round(rng.uniform(30.0, 40.0, len(index))),
    }
    df = pd.DataFrame(data, index=index).astype("float64")
    df.index = df.index.astype("datetime64[ns]")
    return df


df = generate_dataframe()
fig = go.Figure()

for c in df.columns:
    fig.add_trace(
        go.Scatter(
            x=df.index,
            y=df[c],
            name=c,
            mode="lines",
        )
    )
    # Last point marker + label
    # SOMETHING HERE MAKES IT FAIL
    last_idx = df[c].last_valid_index()
    if last_idx is not None:
        last_val = df.loc[last_idx, c]
        fig.add_trace(
            go.Scatter(
                x=[last_idx],
                y=[last_val],
                mode="markers",
                showlegend=False,
                hoverinfo="skip",
            )
        )


fig.write_image("plot1.png")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions