Uh oh!
There was an error while loading. Please reload this page.
default hash savefig format - #160
Conversation
bjlittle
commented
May 21, 2022
Okay, wowzers... can anyone explain the test failure behaviour of |
ConorMacBride
commented
May 21, 2022
Very strange. It seems that passing |
ConorMacBride
commented
May 21, 2022
The hashes are different on |
ConorMacBride
commented
May 21, 2022
Yes, the tests pass on MPL 3.5.1. Can you pin this to Line 29 in e387618 Hopefully this is something that the perceptual hashes can solve, as we really should be testing against the latest bug fixes from matplotlib! |
bjlittle
commented
May 21, 2022
Awesome detective work 🕵️ |
@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.
@ConorMacBride We should make an issue to unpin this, right?
There was a problem hiding this comment.
We no longer need to change this.
ConorMacBride
commented
May 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 in e387618 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
commented
May 23, 2022
Agreed. |
That's pretty much my experience so far. We've opted for a |
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
commented
May 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
commented
May 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
commented
May 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.
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.
We no longer need to change this.
This PR addresses issue #152, by ensuring that a default
format='png'is injected to thesavefigkwargs when generating a hash.Closes#152