Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ENH: raise a more informative error #1533

Merged
merged 3 commits into from

3 participants

@jakevdp

Raise a more informative error when save is called and no animation writers are available on the system. Previously this situation would lead to an IndexError at the line writer = writers.list()[0]

@pelson
Collaborator

Thanks @jakevdp. My biggest problem with this change is that I now have to use the writers registry (which I don't use). I think a better approach would be to add a new method on to the writers registry which can return the "first" (in speech marks because we have inconsistent ordering due to use of a dictionary) available writer, or raise an exception (not an IndexError as it used to).

Other than that, I'm in favour of seeing this exception improved.

Thanks,

@jakevdp

Ah, I didn't think of the possibility of people passing anything but a string to the writer argument... yes, that should be improved.

@jakevdp

This update should fix the issue.

lib/matplotlib/animation.py
@@ -657,7 +657,13 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
else:
import warnings
warnings.warn("MovieWriter %s unavailable" % writer)
- writer = writers.list()[0]
+
+ try:
+ writer = writers.list()[0]
+ except:
@pelson Collaborator
pelson added a note

I'm sorry for being so picky, but ideally we should avoid bare try..except blocks. I think your trying to improve the IndexError which ensues when there are no writers? In which case, would you mind updating this to a try ... except IndexError:.

After that, its good to merge - honest! :smile:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dmcdougall dmcdougall merged commit dd92a43 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 25, 2012
  1. @jakevdp
Commits on Nov 26, 2012
  1. @jakevdp
Commits on Nov 28, 2012
  1. @jakevdp
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/matplotlib/animation.py
View
8 lib/matplotlib/animation.py
@@ -657,7 +657,13 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
else:
import warnings
warnings.warn("MovieWriter %s unavailable" % writer)
- writer = writers.list()[0]
+
+ try:
+ writer = writers.list()[0]
+ except IndexError:
+ raise ValueError("Cannot save animation: no writers are "
+ "available. Please install mencoder or "
+ "ffmpeg to save animations.")
verbose.report('Animation.save using %s' % type(writer),
level='helpful')
Something went wrong with that request. Please try again.