Skip to content
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

PdfPages: add option to delete empty file when closed #2453

Merged
merged 3 commits into from Sep 30, 2013

Conversation

megies
Copy link
Contributor

@megies megies commented Sep 23, 2013

I have automatic signal processing scripts with nested loops that output plots in multipage pdfs.
Sometimes, though, these loops do not produce a single pdf page and I ended up with loads of broken/empty pdf files. I found it useful to be able to tell the PdfPage object at initialization (using with statement) that it should go straight to trash if it ends up empty.

I wasn't sure if this was to be considered too special to go into the main repo but I figured opening a PR can't hurt too much. Also, the current behavior (keep empty pdf files)

  • PdfPages objects can be told at initialization to delete the pdf file
    when closed, if no page was actually plotted
  • keep the default to not delete empty pdf files so current behavior is
    not changed
  • also some basic tests for it

 - PdfPages objects can be told at initialization to delete the pdf file
   when closed, if no page was actually plotted
 - keep the default to not delete empty pdf files so current behavior is
   not changed
 - also some basic tests for it
pdf.savefig()
assert os.path.exists(filename)
os.remove(filename)
with NamedTemporaryFile(delete=False) as tmp:
Copy link
Member

Choose a reason for hiding this comment

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

What does this last block add?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the comment in line 75 covers both blocks actually, but you're right maybe, I can split it up for clarity.

@megies
Copy link
Contributor Author

megies commented Sep 24, 2013

I've refactored docstrings for PdfPages, maybe somebody can give it a quick double check if its correct with MEP10.

@mdboom
Copy link
Member

mdboom commented Sep 30, 2013

Looks good to me.

mdboom added a commit that referenced this pull request Sep 30, 2013
PdfPages: add option to delete empty file when closed
@mdboom mdboom merged commit 2b614cf into matplotlib:master Sep 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants