- Notifications
You must be signed in to change notification settings - Fork49
default hash savefig format#160
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
bjlittle commentedMay 21, 2022
Okay, wowzers... can anyone explain thetest failure behaviour of |
ConorMacBride commentedMay 21, 2022
Very strange. It seems that passing |
ConorMacBride commentedMay 21, 2022
The hashes are different on |
ConorMacBride commentedMay 21, 2022
Yes, the tests pass on MPL 3.5.1. Can you pin this to Line 29 ine387618
Hopefully this is something that the perceptual hashes can solve, as we really should be testing against the latest bug fixes from matplotlib! |
bjlittle commentedMay 21, 2022
Awesome detective work 🕵️ |
bjlittle commentedMay 21, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@ConorMacBride If the What are the implications to the community if we bank this new default |
| mpl33:matplotlib==3.3.* | ||
| mpl34:matplotlib==3.4.* | ||
| mpl35:matplotlib==3.5.* | ||
| mpl35:matplotlib==3.5.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@ConorMacBride We should make an issue to unpin this, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We no longer need to change this.
ConorMacBride commentedMay 22, 2022
I presume the default hash size, high frequency factor and hamming tolerance can be tuned to a value that minimises, what an average user would consider, a test passing incorrectly? (I would expect most of the I suspect
From reading the pytest-mpl/pytest_mpl/plugin.py Line 601 ine387618
I've added some code below. In the default case, both hashes are the same so no breaking change. However, if a custom backend has been specified, passing So, if the user asks for a different backend, setting To not interfere with the requested backend, I think we should only set Click for codeimportioimporthashlibimportmatplotlibimportmatplotlib.pyplotaspltdef_hash_file(in_stream):""" Hashes an already opened file. """in_stream.seek(0)buf=in_stream.read()hasher=hashlib.sha256()hasher.update(buf)returnhasher.hexdigest()defhash(**kwargs):fig=plt.figure()ax=fig.add_subplot(1,1,1)ax.plot([1,3,2,4])imgdata=io.BytesIO()fig.savefig(imgdata,**kwargs)plt.close()return_hash_file(imgdata)# Default (pytest-mpl sets agg)matplotlib.use("agg")print(hash())# b7d7754ed51a78949e119e3900b72b4123fcc3674fd6a5750b9a93f7091293abprint(hash(format="png"))# b7d7754ed51a78949e119e3900b72b4123fcc3674fd6a5750b9a93f7091293ab# User passes backend="svg" to pytest-mpl decoratormetadata= {"Creator":None,"Date":None,"Format":None,"Type":None}matplotlib.use("svg")print(hash(metadata=metadata))# 81910e47aa39455d96c41893f73793c65b5405af14af7919dbe8a7172e004fcfprint(hash(metadata=metadata))# 0bf13ec69c253c6a8d3b6b004aa4855e343e5f40a79106e87fee72c208f7de89print(hash(format="png"))# b7d7754ed51a78949e119e3900b72b4123fcc3674fd6a5750b9a93f7091293ab |
bjlittle commentedMay 23, 2022
Agreed. |
bjlittle commentedMay 23, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
That's pretty much my experience so far. We've opted for a |
bjlittle commentedMay 23, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've re-ran and updated a notebook that I wrote to initially investigate and play with To create a conda environment to run it, simply Interestingly, changing the colormap on a plot is detected by |
bjlittle commentedMay 23, 2022
Overall, I wait for you guys to come to a consensus and advise on what to do next here with this PR. |
Cadair commentedMay 23, 2022
I think matplotlib puts metadata into the png including the version iirc. I think we can turn that off. See the metadata keyword argument here:https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html and more info on png here:https://matplotlib.org/stable/api/backend_agg_api.html#matplotlib.backends.backend_agg.FigureCanvasAgg.print_png |
ConorMacBride commentedMay 27, 2022
Given how effective removing the metadata version number was in#163 I think we should definitely remove it by default and make it a breaking change (for |
ConorMacBride left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I don't think we need to set this for the reasons in the second half of#160 (comment). Should we just close this PR?
| mpl33:matplotlib==3.3.* | ||
| mpl34:matplotlib==3.4.* | ||
| mpl35:matplotlib==3.5.* | ||
| mpl35:matplotlib==3.5.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We no longer need to change this.
Uh oh!
There was an error while loading.Please reload this page.
This PR addresses issue#152, by ensuring that a default
format='png'is injected to thesavefigkwargs when generating a hash.Closes#152