Skip to content

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

Closed
wants to merge 6 commits into from
Closed

fixed pdf backend saving 2nd go #8674

wants to merge 6 commits into from

Conversation

ghost
Copy link

@ghost ghost commented May 27, 2017

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

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@ghost ghost changed the title fixed pdf backend saving and modified pdf to eps blank/nonblank compa… fixed pdf backend saving 2nd go May 27, 2017
Copy link
Member

@dstansby dstansby left a 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:
Copy link
Member

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.

Copy link
Author

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
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Will fix

Copy link
Member

@QuLogic QuLogic May 30, 2017

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Author

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)
Copy link
Member

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?

Copy link
Author

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.

Copy link
Author

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.

Copy link
Member

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 dstansby added this to the 2.0.3 (next bug fix release) milestone May 29, 2017
@ghost
Copy link
Author

ghost commented Jun 3, 2017

@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')
Copy link
Member

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

@tacaswell
Copy link
Member

@Tuan333 I am going to push a commit to your branch removing the fixture decorator which I think will fix the coverage issues.

@tacaswell
Copy link
Member

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.

@tacaswell
Copy link
Member

Closing as commits are moved to #8850

@tacaswell tacaswell closed this Jul 10, 2017
@QuLogic QuLogic modified the milestones: 2.1 (next point release), 2.0.3 (next bug fix release) Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants