Skip to content

Commit 5b65329

Browse files
authored
Merge pull request #4190 from plotly/px-pandas2
Px pandas2
2 parents 3eb3ee4 + 284e9bc commit 5b65329

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

Diff for: .circleci/config.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ commands:
9292
cd packages/python/plotly
9393
. venv/bin/activate
9494
pytest -x test_init/test_lazy_imports.py
95-
9695
test_orca:
9796
parameters:
9897
py:
@@ -231,7 +230,7 @@ jobs:
231230
# Percy
232231
python_37_percy:
233232
docker:
234-
- image: cimg/python:3.7-browsers
233+
- image: cimg/python:3.9-browsers
235234
environment:
236235
PERCY_ENABLED: True
237236
PERCY_PROJECT: plotly/plotly.py
@@ -253,12 +252,23 @@ jobs:
253252
pip install --upgrade pip wheel
254253
pip install -e ./packages/python/plotly
255254
pip install -e ./packages/python/plotly-geo
256-
pip install -r ./packages/python/plotly/test_requirements/requirements_37_optional.txt
255+
pip install -r ./packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt
256+
- run:
257+
name: Build html figures (Pandas 2)
258+
command: |
259+
. venv/bin/activate
260+
python test/percy/plotly-express.py
257261
- run:
258-
name: Build html figures
262+
name: Build html figures (Pandas 1) and compare
259263
command: |
260264
. venv/bin/activate
265+
mkdir test/percy/pandas2
266+
mv test/percy/*.html test/percy/pandas2/
267+
# 1.1 is the earliest minor with Py3.9 wheels
268+
pip install "pandas==1.1.5"
261269
python test/percy/plotly-express.py
270+
python test/percy/compare-pandas.py
271+
rm -rf test/percy/pandas2
262272
- run:
263273
name: Run percy snapshots
264274
command: |

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ packages/python/plotly/jupyterlab_plotly/labextension/
5454
packages/python/plotly/jupyterlab_plotly/nbextension/index.js*
5555

5656
test/percy/*.html
57+
test/percy/pandas2/*.html

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [UNRELEASED]
6+
7+
### Fixed
8+
- Fixed another compatibility issue with Pandas 2.0, just affecting `px.*(line_close=True)` [[#4190](https://github.com/plotly/plotly.py/pull/4190)]
9+
510
## [5.14.1] - 2023-04-05
611

712
### Fixed

Diff for: packages/python/plotly/plotly/express/_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
268268
fit information to be used for trendlines
269269
"""
270270
if "line_close" in args and args["line_close"]:
271-
trace_data = trace_data.append(trace_data.iloc[0])
271+
trace_data = pd.concat([trace_data, trace_data.iloc[:1]])
272272
trace_patch = trace_spec.trace_patch.copy() or {}
273273
fit_results = None
274274
hover_header = ""

Diff for: packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
requests==2.25.1
22
tenacity==6.2.0
3-
pandas==2.0.0
3+
pandas==2.0.1
44
numpy==1.20.3
55
xarray==0.17.0
66
statsmodels

Diff for: test/percy/compare-pandas.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import difflib
2+
import json
3+
import os
4+
5+
os.chdir(os.path.dirname(__file__))
6+
7+
8+
def clean_float(numstr):
9+
# round numbers to 3 digits, to remove floating-point differences
10+
return round(float(numstr), 3)
11+
12+
13+
def get_fig(html):
14+
# strip off all the rest of the html and js
15+
fig_str = html[html.index("[{", html.rindex("Plotly.newPlot(")) :]
16+
fig_str = fig_str[: fig_str.index("} ") + 1]
17+
data, layout, config = json.loads(f"[{fig_str}]", parse_float=clean_float)
18+
fig_dict = dict(data=data, layout=layout, config=config)
19+
return json.dumps(fig_dict, indent=2).splitlines(keepends=True)
20+
21+
22+
for filename in os.listdir("pandas2"):
23+
with open(filename, encoding="utf-8") as f1:
24+
with open(os.path.join("pandas2", filename)) as f2:
25+
fig1 = get_fig(f1.read())
26+
fig2 = get_fig(f2.read())
27+
if any(l1 != l2 for l1, l2 in zip(fig1, fig2)):
28+
print("".join(difflib.unified_diff(fig1, fig2)))
29+
raise ValueError(f"Pandas 1/2 difference in {filename}")

0 commit comments

Comments
 (0)