Skip to content

Skip comparing few mocks between pandas v1 and v2 that produce slightly different values related to small rounding errors #4814

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

Merged
merged 2 commits into from
Oct 22, 2024
Merged
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
33 changes: 20 additions & 13 deletions test/percy/compare-pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,32 @@
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)
data, layout, config = json.loads(f"[{fig_str}]")
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}")
if filename not in [
"density_mapbox.html",
"density_map.html",
"scatter_hover.html",
"scatter_mapbox.html",
"scatter_map.html",
"line.html",
"choropleth.html",
"line_mapbox.html",
"line_map.html",
"scatter_log.html",
]:
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}")