Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/check-js-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
on: push
on:
push:
branches:
- main
pull_request:
types: [opened, reopened]
paths:
- 'js/**'
- 'plotly/labextension/**'

name: Check JS build

jobs:
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/run-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
run: |
uv venv
source .venv/bin/activate
uv sync --extra dev_optional
uv sync --extra dev_optional --extra dev_pandas3
python --version
- name: Test core
run: |
Expand Down Expand Up @@ -84,14 +84,22 @@ jobs:
python -m pytest -x test_init/test_lazy_imports.py

test-optional-legacy-pandas:
name: Optional tests, Pandas 1 (Python 3.9, Pandas 1.2.4)
name: Optional tests (Python ${{ matrix.python-version }}, pandas ${{ matrix.pandas-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.9"
pandas-version: "1"
- python-version: "3.11"
pandas-version: "2"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.9"
python-version: ${{ matrix.python-version }}
- name: Set up Chrome for browser tests
uses: ./.github/actions/setup-chrome-for-pytest
- name: Set up uv
Expand All @@ -100,8 +108,7 @@ jobs:
run: |
uv venv
source .venv/bin/activate
uv sync --extra dev_optional
uv pip install pandas==1.2.4 numpy==1.26.4
uv sync --extra dev_optional --extra dev_pandas${{ matrix.pandas-version }}
- name: Test core
run: |
source .venv/bin/activate
Expand All @@ -128,7 +135,7 @@ jobs:
python -m pytest -x test_init/test_lazy_imports.py

test-kaleido-v0:
name: Optional tests (Kaleido only), Kaleido v0 (Python 3.12, Kaleido v0.2.1)
name: Optional tests (Kaleido only), Kaleido v0 (Python 3.12, kaleido 0.2.1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason. I changed pandas to lowercase in the other job names so just changed this one for consistency

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed
- Update tests to be compatible with numpy 2.4 [[#5522](https://github.com/plotly/plotly.py/pull/5522)], with thanks to @thunze for the contribution!


## [6.7.0] - 2026-04-09

Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,26 @@ dev = [
"plotly[dev_optional]"
]

# The following extras are intended for use in CI only
dev_pandas1 = [
"pandas>=1,<2",
"numpy>=1,<2",
"setuptools<82"
]
dev_pandas2 = [
"pandas>=2,<3",
]
dev_pandas3 = [
"pandas>=3;python_version>='3.11'",
]

[tool.uv]
exclude-newer = "72 hours"
conflicts = [
[{ extra = "dev_pandas1" }, { extra = "dev_pandas2" }],
[{ extra = "dev_pandas1" }, { extra = "dev_pandas3" }],
[{ extra = "dev_pandas2" }, { extra = "dev_pandas3" }],
]

[project.scripts]
plotly_get_chrome = "plotly.io._kaleido:plotly_get_chrome"
Expand Down
34 changes: 31 additions & 3 deletions tests/test_optional/test_px/test_px_functions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import plotly.express as px
import plotly.graph_objects as go
from numpy.testing import assert_array_equal
import narwhals.stable.v1 as nw
import numpy as np
from numpy.testing import assert_array_equal
from packaging.version import Version
import pandas
import plotly.express as px
import plotly.graph_objects as go
from polars.exceptions import InvalidOperationError
import pytest

from .conftest import pandas_pyarrow_constructor


def _pandas_version_at_least(version: str) -> bool:
return Version(pandas.__version__) >= Version(version)


def _compare_figures(go_trace, px_fig):
"""Compare a figure created with a go trace and a figure created with
Expand Down Expand Up @@ -153,6 +161,11 @@ def test_sunburst_treemap_colorscales():


def test_sunburst_treemap_with_path(constructor):
if _pandas_version_at_least("3.0.0") and constructor == pandas_pyarrow_constructor:
pytest.skip(
"known issue with pandas 3 + pandas_pyarrow_constructor + px.sunburst() (https://github.com/plotly/plotly.py/issues/5571)"
)

vendors = ["A", "B", "C", "D", "E", "F", "G", "H"]
sectors = [
"Tech",
Expand Down Expand Up @@ -249,6 +262,11 @@ def test_sunburst_treemap_with_path_and_hover(backend):


def test_sunburst_treemap_with_path_color(constructor):
if _pandas_version_at_least("3.0.0") and constructor == pandas_pyarrow_constructor:
pytest.skip(
"known issue with pandas 3 + pandas_pyarrow_constructor + px.sunburst() (https://github.com/plotly/plotly.py/issues/5571)"
)

vendors = ["A", "B", "C", "D", "E", "F", "G", "H"]
sectors = [
"Tech",
Expand Down Expand Up @@ -327,6 +345,11 @@ def test_sunburst_treemap_with_path_color(constructor):


def test_sunburst_treemap_column_parent(constructor):
if _pandas_version_at_least("3.0.0") and constructor == pandas_pyarrow_constructor:
pytest.skip(
"known issue with pandas 3 + pandas_pyarrow_constructor + px.sunburst() (https://github.com/plotly/plotly.py/issues/5571)"
)

vendors = ["A", "B", "C", "D", "E", "F", "G", "H"]
sectors = [
"Tech",
Expand Down Expand Up @@ -354,6 +377,11 @@ def test_sunburst_treemap_column_parent(constructor):


def test_sunburst_treemap_with_path_non_rectangular(constructor):
if _pandas_version_at_least("3.0.0") and constructor == pandas_pyarrow_constructor:
pytest.skip(
"known issue with pandas 3 + pandas_pyarrow_constructor + px.sunburst() (https://github.com/plotly/plotly.py/issues/5571)"
)

vendors = ["A", "B", "C", "D", None, "E", "F", "G", "H", None]
sectors = [
"Tech",
Expand Down
69 changes: 54 additions & 15 deletions tests/test_optional/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,24 @@ def test_encode_customdata_datetime_series(self):
fig_json = _json.dumps(
fig, cls=utils.PlotlyJSONEncoder, separators=(",", ":"), sort_keys=True
)
self.assertTrue(
fig_json.startswith(
'{"data":[{"customdata":["2010-01-01T00:00:00.000000000","2010-01-02T00:00:00.000000000"]'

fig_from_json = Figure(_json.loads(fig_json))

import pandas

if Version(pandas.__version__) >= Version("3.0.0"):
# Starting in pandas 3, datetimes have ms precision by default
# https://pandas.pydata.org/docs/whatsnew/v3.0.0.html#datetime-timedelta-resolution-inference
assert fig_from_json.data[0].customdata == (
"2010-01-01T00:00:00.000000",
"2010-01-02T00:00:00.000000",
)
else:
# Before pandas 3, datetimes have ns precision by default
assert fig_from_json.data[0].customdata == (
"2010-01-01T00:00:00.000000000",
"2010-01-02T00:00:00.000000000",
)
)

def test_encode_customdata_datetime_homogeneous_dataframe(self):
df = pd.DataFrame(
Expand All @@ -332,13 +345,24 @@ def test_encode_customdata_datetime_homogeneous_dataframe(self):
fig_json = _json.dumps(
fig, cls=utils.PlotlyJSONEncoder, separators=(",", ":"), sort_keys=True
)
self.assertTrue(
fig_json.startswith(
'{"data":[{"customdata":'
'[["2010-01-01T00:00:00.000000000","2011-01-01T00:00:00.000000000"],'
'["2010-01-02T00:00:00.000000000","2011-01-02T00:00:00.000000000"]'

fig_from_json = Figure(_json.loads(fig_json))

import pandas

if Version(pandas.__version__) >= Version("3.0.0"):
# Starting in pandas 3, datetimes have ms precision by default
# https://pandas.pydata.org/docs/whatsnew/v3.0.0.html#datetime-timedelta-resolution-inference
assert fig_from_json.data[0].customdata == (
["2010-01-01T00:00:00.000000", "2011-01-01T00:00:00.000000"],
["2010-01-02T00:00:00.000000", "2011-01-02T00:00:00.000000"],
)
else:
# Before pandas 3, datetimes have ns precision by default
assert fig_from_json.data[0].customdata == (
["2010-01-01T00:00:00.000000000", "2011-01-01T00:00:00.000000000"],
["2010-01-02T00:00:00.000000000", "2011-01-02T00:00:00.000000000"],
)
)

def test_encode_customdata_datetime_inhomogeneous_dataframe(self):
df = pd.DataFrame(
Expand Down Expand Up @@ -384,11 +408,26 @@ def test_datetime_dot_date(self):
def test_numpy_datetime64(self):
a = pd.date_range("2011-07-11", "2011-07-13", freq="D").values
j1 = _json.dumps(a, cls=utils.PlotlyJSONEncoder)
assert (
j1 == '["2011-07-11T00:00:00.000000000", '
'"2011-07-12T00:00:00.000000000", '
'"2011-07-13T00:00:00.000000000"]'
)

from_json = _json.loads(j1)

import pandas

if Version(pandas.__version__) >= Version("3.0.0"):
# Starting in pandas 3, datetimes have ms precision by default
# https://pandas.pydata.org/docs/whatsnew/v3.0.0.html#datetime-timedelta-resolution-inference
assert from_json == [
"2011-07-11T00:00:00.000000",
"2011-07-12T00:00:00.000000",
"2011-07-13T00:00:00.000000",
]
else:
# Before pandas 3, datetimes have ns precision by default
assert from_json == [
"2011-07-11T00:00:00.000000000",
"2011-07-12T00:00:00.000000000",
"2011-07-13T00:00:00.000000000",
]

def test_pil_image_encoding(self):
img_path = os.path.join(
Expand Down
Loading
Loading