address FuncAnimantion trying to take lengths of generators#2634
Conversation
|
The "closes" part of the commit message is pointing to the wrong issue. |
If an iterable is passed into `FuncAnimation` check if it has `__len__` before trying to take it's length closes matplotlib#1769
|
fixed, transposed the last two digits. |
|
From my experience with this module, I think this is just fine. However, I think this clashes with the new single-dispatch generic functions: http://www.python.org/dev/peps/pep-0443/ (or at least, we may be needing to rethink how we duck-type. |
|
Would it be better to do this with a try/catch block? I was trying to be clever and was looking for the moral equivalent of |
|
I think so. And I certainly don't think it is "wrong", per se, as I have |
|
As the only thing this is setting is the number of frames to cache, and it behaves sensibly if |
There was a problem hiding this comment.
What happens if save_count isn't set. Is this a problem?
There was a problem hiding this comment.
Oh. Urgh, it defaults to 100. Perhaps we are better assuming that the generator isn't infinite and casting it to a list?
There was a problem hiding this comment.
I don't see why that is a problem, it will just keep a rolling buffer of that length. It isn't useful, but it's not really harmful. I might also be confused.
I think it is important to keep the ability to have infinite generators, this is a quick way to spin up realtime-ish diagnostic displays.
There was a problem hiding this comment.
Ah, yes, thanks @tacaswell - I misunderstood what thee save count was doing. Ignore me 😄
There was a problem hiding this comment.
That said, I have never figured out where the saved frames are used....
I am not sure if it is precursor work for a feature that never got finished or I just don't understand what it is doing.
There was a problem hiding this comment.
@tacaswell - I think we should try to add a test case (hopefully it will be quite straight forward) which exercises this code path.
does not have a length.
|
@pelson Test added |
iterator test actually runs
There was a problem hiding this comment.
Should there be an assertion here? I appreciate the fact that you're calling the constructor, and that before it was raising an Exception, but it'd be nice to test the attributes which you expect to have been set.
There was a problem hiding this comment.
Given the discussion above about the value it defaults to and my confusion of what this value actually does (does it make sense to keep a rolling buffer of an infinite generator?) I think it is better to just test 'does it blow up' here due to the high chance of what it defaults to changing in the (near) future.
|
@pelson any further thoughts on this PR? |
address FuncAnimantion trying to take lengths of generators
|
Yep. It's good to go! Cheers @tacaswell. |
If an iterable is passed into
FuncAnimationcheck if it has__len__before trying to take it's lengthcloses #1769