Skip to content
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

Px pandas2 #4190

Merged
merged 7 commits into from
May 5, 2023
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
18 changes: 14 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ commands:
cd packages/python/plotly
. venv/bin/activate
pytest -x test_init/test_lazy_imports.py

test_orca:
parameters:
py:
Expand Down Expand Up @@ -231,7 +230,7 @@ jobs:
# Percy
python_37_percy:
docker:
- image: cimg/python:3.7-browsers
- image: cimg/python:3.9-browsers
environment:
PERCY_ENABLED: True
PERCY_PROJECT: plotly/plotly.py
Expand All @@ -253,12 +252,23 @@ jobs:
pip install --upgrade pip wheel
pip install -e ./packages/python/plotly
pip install -e ./packages/python/plotly-geo
pip install -r ./packages/python/plotly/test_requirements/requirements_37_optional.txt
pip install -r ./packages/python/plotly/test_requirements/requirements_39_pandas_2_optional.txt
- run:
name: Build html figures (Pandas 2)
command: |
. venv/bin/activate
python test/percy/plotly-express.py
- run:
name: Build html figures
name: Build html figures (Pandas 1) and compare
command: |
. venv/bin/activate
mkdir test/percy/pandas2
mv test/percy/*.html test/percy/pandas2/
# 1.1 is the earliest minor with Py3.9 wheels
pip install "pandas==1.1.5"
python test/percy/plotly-express.py
python test/percy/compare-pandas.py
rm -rf test/percy/pandas2
- run:
name: Run percy snapshots
command: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ packages/python/plotly/jupyterlab_plotly/labextension/
packages/python/plotly/jupyterlab_plotly/nbextension/index.js*

test/percy/*.html
test/percy/pandas2/*.html
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [UNRELEASED]

### Fixed
- Fixed another compatibility issue with Pandas 2.0, just affecting `px.*(line_close=True)` [[#4190](https://github.com/plotly/plotly.py/pull/4190)]

## [5.14.1] - 2023-04-05

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
fit information to be used for trendlines
"""
if "line_close" in args and args["line_close"]:
trace_data = trace_data.append(trace_data.iloc[0])
trace_data = pd.concat([trace_data, trace_data.iloc[:1]])
trace_patch = trace_spec.trace_patch.copy() or {}
fit_results = None
hover_header = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
requests==2.25.1
tenacity==6.2.0
pandas==2.0.0
pandas==2.0.1
numpy==1.20.3
xarray==0.17.0
statsmodels
Expand Down
29 changes: 29 additions & 0 deletions test/percy/compare-pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import difflib
import json
import os

os.chdir(os.path.dirname(__file__))


def clean_float(numstr):
# round numbers to 3 digits, to remove floating-point differences
return round(float(numstr), 3)


def get_fig(html):
# strip off all the rest of the html and js
fig_str = html[html.index("[{", html.rindex("Plotly.newPlot(")) :]
fig_str = fig_str[: fig_str.index("} ") + 1]
data, layout, config = json.loads(f"[{fig_str}]", parse_float=clean_float)
fig_dict = dict(data=data, layout=layout, config=config)
return json.dumps(fig_dict, indent=2).splitlines(keepends=True)


for filename in os.listdir("pandas2"):
with open(filename, encoding="utf-8") as f1:
with open(os.path.join("pandas2", filename)) as f2:
fig1 = get_fig(f1.read())
fig2 = get_fig(f2.read())
if any(l1 != l2 for l1, l2 in zip(fig1, fig2)):
print("".join(difflib.unified_diff(fig1, fig2)))
raise ValueError(f"Pandas 1/2 difference in {filename}")