-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fixed pdf backend saving 2nd go #8674
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
Conversation
…rison and unit test case
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.
A couple of small changes/questions, but overall this looks good.
plt.subplot() | ||
plt.axis('off') | ||
plt.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none') | ||
try: |
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 think this try/except block can go; if the next line throws and exception the test will automatically fail.
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.
Yes. Will fix this
plt.savefig("figure.eps", format='eps') | ||
result = compare_images('figure.pdf', 'figure.eps', 0) | ||
assert result is None | ||
from os import remove |
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.
The following line can just be os.remove('figure.eps')
, and then this import line isn't needed.
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.
Noted. Will fix
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.
These files should be saved in a temporary directory (use the (tmpdir
fixture), and you won't need to delete them.
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.
But also, I thought @tacaswell said this wasn't necessary.
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.
Either way on this staying or not, but 👍 to using the tempdir
fixture.
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.
ah, tempdir
fixture sounds cool, I didn't know what it was before. Will fix this then. Resubmit tomorrow.
|
||
def test_pdf_savefig_when_color_is_none(): | ||
backup_params = mpl.rcParams.copy() | ||
mpl.rcParams.update(mpl.rcParamsDefault) |
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.
Is there a particular reason why the rcParams have to be updated to the defaults?
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 will have to get back on this one when I'm back from work. It was two days ago, can't recall the reason on the spot.
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.
@dstansby The reason for using default rcParams is that in testing environment, rcParams['_internal.classic_mode'] == True
and the resulting code path of this setting does not go through the error i.e. gc._rgb
is always not None
. In other words, this error (and the required fix) is very specific to the setting where rcParams['_internal.classic_mode'] == False
, which happens to be the default behaviour. Admittedly, I over-killed the setting by set everything back to default rather than a single setting.
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.
All settings are reset at the beginning of tests; use @pytest.mark.style('default')
to change styles.
@dstansby @QuLogic @tacaswell some codecov test fails, but given this is a very simple fix, I wonder if these failures can be overlooked. |
@@ -191,3 +193,18 @@ def psfont(*args, **kwargs): | |||
ax.text(0.5, 0.5, 'hello') | |||
with tempfile.TemporaryFile() as tmpfile, pytest.raises(ValueError): | |||
fig.savefig(tmpfile, format='pdf') | |||
|
|||
|
|||
@pytest.fixture(scope='function') |
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.
Did you mean to make this a new fixture? The coverage is failing because this is never getting run
@Tuan333 I am going to push a commit to your branch removing the |
Actually it seems @Tuan333 has deleted their Matplotlib fork, going to grab these commits, add the extra commit, push to my fork and make a new PR. |
Closing as commits are moved to #8850 |
PR Summary
The second pull request to address #8142 to address @tacaswell 's comment in #8644. Added a test case to compare generated figures using pdf backend with eps backend (the later does not have this bug). Added some small fix to testing facility in the process. Note that the current pdf to eps comparison function is probably only worthwhile when comparing blank/non-blank images
PR Checklist