Skip to content

Deprecate truncating saved unsized anims to 100 frames. #10301

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

Merged
merged 1 commit into from
Jan 28, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 23, 2018

To test that the deprecation is working, uncomment the ani.save(...)
line in the simple_anim.py example and modify the anim's save_count.

Animations that happened to generate exactly 100 frames without
truncation will incorrectly trigger a warning; not sure we can do much
about it (because after the 100th frame is generated there is no way to
know whether another frame is coming except by actually calling next()
on the generator, which we do not want to do).

cf discussion in #8278.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

So much code just to deprecate that behavior. sigh

@anntzer anntzer force-pushed the dont-truncate-anims branch from c7a4328 to eaf3e66 Compare January 24, 2018 22:51
for anim, d in zip(all_anim, data):
if d is _truncated_sentinel:
Copy link
Member

Choose a reason for hiding this comment

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

Just for my learning, why do you need _trundated_sentinel in here, versus just counting to 100?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To only trigger the warning in the case the user passed in a generator. If the user passed in just a very long but explicit list, the previous code would (correctly) not truncate it, and we don't want to trigger a warning in this case.

Copy link
Member

Choose a reason for hiding this comment

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

Can't you do this in a clearer way (i.e. w/o itertools.chain)? I guess I'd be OK w/ this construct if it saves a bunch of code, or maybe this is really the only way to do it, but it seems this check could be less opaque.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAICT I need to tag a sentinel at the end of the generator. But this needs to be done without actually running the generator first (because that can require arbitrarily large resources); so itertools.chain is literally the way to do that.
Alternatively I would need to keep another flag around saying "this is a generator-based animation, please check whether we reached the 100th frame", which I guess works too but I am not sure it's simpler...

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 is a reasonable way to implement this, it keeps the state all in one place.

Copy link
Member

Choose a reason for hiding this comment

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

If this is the best way to do it, it would help if there was a bit of a comment in the code explaining what is going on, in case you both decide to take up extreme crocheting and don't stop around here anymore.

Copy link
Contributor Author

@anntzer anntzer Jan 27, 2018

Choose a reason for hiding this comment

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

Actually I think I figured out a less obfuscated way to implement this... pushed.

@tacaswell tacaswell added this to the v2.2 milestone Jan 26, 2018
@anntzer anntzer force-pushed the dont-truncate-anims branch from eaf3e66 to acb6d5c Compare January 27, 2018 02:39
"2.2", "FuncAnimation.save has truncated your animation "
"to 100 frames. In the future, no such truncation will "
"occur; please pass 'save_count' accordingly.")
try:
Copy link
Member

Choose a reason for hiding this comment

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

Sorry to be a pain, but why is this second block needed? Are you going to keep returning frames even though the saving is not saving any more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because I'm an idiot...

To test that the deprecation is working, uncomment the `ani.save(...)`
line in the simple_anim.py example and modify the anim's save_count.

Animations that happened to generate exactly 100 frames without
truncation will incorrectly trigger a warning; not sure we can do much
about it (because after the 100th frame is generated there is no way to
know whether another frame is coming except by actually calling next()
on the generator, which we do not want to do).
@anntzer anntzer force-pushed the dont-truncate-anims branch from acb6d5c to 15c6d59 Compare January 27, 2018 06:25
Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Ok, I really like this version now. Nice and clean.

@jklymak jklymak merged commit f68f9a1 into matplotlib:master Jan 28, 2018
@anntzer anntzer deleted the dont-truncate-anims branch January 28, 2018 00:57
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
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.

5 participants