Skip to content

Commit 9c04542

Browse files
committed
pandas 1/2 px comparison: looser equality of just the figure spec
1 parent 06d0360 commit 9c04542

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Diff for: .circleci/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ jobs:
275275
npx percy snapshot -c test/percy/snapshots.yml test/percy/
276276
rm test/percy/*.html
277277
rm -rf test/percy/pandas2
278+
- store_artifacts:
279+
path: test/percy
278280

279281
# Chart studio
280282
python_37_chart_studio:

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

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
import difflib
2+
import json
13
import os
24

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

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

0 commit comments

Comments
 (0)