Skip to content

Deprecate attributes and expire deprecation in animation - #24131

Merged
greglucas merged 10 commits into
matplotlib:mainfrom
oscargus:animationdeprecations
Dec 29, 2022
Merged

greglucas merged 10 commits into
matplotlib:mainfrom
oscargus:animationdeprecations

Conversation

@oscargus

@oscargus oscargus commented Oct 8, 2022

Copy link
Copy Markdown
Member

PR Summary

Not sure if the deprecation warning could actually be triggered without setting anim.save_count after creating the animation. Anyway, it's been around from 2.2 so I think this is OK.

The Python bug mentioned seems to have been fixed in 3.8(?): python/cpython#74722

Privatized the save_count attribute as well as the repeat attribute. I cannot really see a use case for changing these after creating the animation.

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@oscargus oscargus added API: changes Changes to the public API, typically requiring deprecation. topic: animation labels Oct 8, 2022
@oscargus oscargus added this to the v3.7.0 milestone Oct 8, 2022
@oscargus
oscargus force-pushed the animationdeprecations branch from 7c7201c to 173e3c1 Compare October 8, 2022 19:57
@oscargus

oscargus commented Oct 10, 2022 •

Copy link
Copy Markdown
Member Author

I do not understand the warnings:

/home/circleci/project/doc/api/_as_gen/matplotlib.animation.ArtistAnimation.rst:33:<autosummary>:1: WARNING: py:obj reference target not found: matplotlib.animation.ArtistAnimation.repeat
/home/circleci/project/lib/matplotlib/animation.py:docstring of matplotlib.animation.FuncAnimation.new_frame_seq:1:<autosummary>:1: WARNING: py:obj reference target not found: matplotlib.animation.FuncAnimation.repeat

These are "new" attributes, in the sense that they are defined in the class rather than in __init__, but only for the purpose of being deprecated. And the save_count attribute does not behave like that. As far as I can tell, none in referenced explicitly, so should be some sort of autodoc thing.

(I know that I've had similar issues with attributes earlier though...)

@QuLogic

QuLogic commented Oct 13, 2022

Copy link
Copy Markdown
Member

I don't think save_count=None was the intended removal, the default of 100 was; see #8278.

@oscargus

Copy link
Copy Markdown
Member Author

Yeah, you are right. Forgot about the purpose a bit in...

@oscargus
oscargus marked this pull request as draft October 13, 2022 15:56
@oscargus
oscargus force-pushed the animationdeprecations branch 3 times, most recently from 09e467c to 11de658 Compare October 15, 2022 10:33
@oscargus

Copy link
Copy Markdown
Member Author

It seems like other parts of the code are relying on save_count being an integer (either provided or computed). So the behaviour discussed in #8278 is not straightforward to obain (which may be the reason it not has been removed since 2.2...).

I guess that one can protect the line

self._save_seq = self._save_seq[-self._save_count:]

with a None-check though...

@oscargus
oscargus force-pushed the animationdeprecations branch 2 times, most recently from 38434b9 to bfec3c4 Compare October 15, 2022 14:56
@story645

Copy link
Copy Markdown
Member

Um what happens in the infinite case if there's no trim?

@QuLogic

QuLogic commented Nov 1, 2022

Copy link
Copy Markdown
Member

Then I think @anntzer has argued that it keeps running unless you specify save_count, just as it does with infinite generators elsewhere.

@story645

story645 commented Nov 1, 2022

Copy link
Copy Markdown
Member

Then I think @anntzer has argued that it keeps running unless you specify save_count, just as it does with infinite generators elsewhere.

how do you save an infinitely running movie?

@oscargus

oscargus commented Nov 7, 2022

Copy link
Copy Markdown
Member Author

how do you save an infinitely running movie?

I guess that there is a file size limit:

Animation size has reached 21248815 bytes, exceeding the limit of 20971520.0. If you're sure you want a larger animation embedded, set the animation.embed_limit rc parameter to a larger value (in MB). This and further frames will be dropped.

@tacaswell

Copy link
Copy Markdown
Member

@story645 is correct that there is an unbounded cache in the case of an inifinte generator that needs to be addressed. The cap on the file size is also only in the jshtml export logic (so we do not make a multi-gigabyte html page 🤣, related if you want to see your browser break build our docs as singlehtml, but I digress).

I pushed some commits that protect against this. There might need to be some more thought around the default value of cache_data_frames as well. I think this is going to hard break some use-cases, but those cases should also have been getting user visible warnings from 2.2 (which is 7 mpl versions).

Also working on the rebase and will add some tests.

@tacaswell

Copy link
Copy Markdown
Member

and we are leaving the footcannon of trying to save an infinite generator, we just won't cache the data along the way. I think we have to leave this as it is unlikely we will be able to solve the halting problem.

@tacaswell
tacaswell force-pushed the animationdeprecations branch from 04e4255 to 1442dc4 Compare December 15, 2022 19:36
@tacaswell
tacaswell marked this pull request as ready for review December 15, 2022 19:37
@tacaswell
tacaswell force-pushed the animationdeprecations branch from 1442dc4 to bbeb86f Compare December 16, 2022 21:49

@tacaswell tacaswell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But I pushed a bunch of code to this PR so this should count as half.

Comment thread lib/matplotlib/tests/test_animation.py Resolved
Comment thread .circleci/config.yml Resolved
@oscargus

Copy link
Copy Markdown
Member Author

I've tried to squash locally, but it just gets messed up. Please squash on merge...

@oscargus

Copy link
Copy Markdown
Member Author

Feels like I've lost track of this, but I think that everything is considered now. The cleanliness may not be correct (in that case it is added yet again, since it is there).

So please squash upon merge... :-)

Comment thread lib/matplotlib/animation.py Resolved
@greglucas

Copy link
Copy Markdown
Contributor

I've tried to squash locally, but it just gets messed up. Please squash on merge...

You should be able to reset to a point you want to be at, including your remote, and then start cleaning up.

git reset --hard origin/animationdeprecations
git rebase -i upstream/main
# clean up
git push --force-with-lease

Comment on lines +54 to +55
ani = animation.FuncAnimation(fig, run, data_gen, interval=100, init_func=init,
save_count=100)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this needed for sphinx-gallery? There isn't otherwise any saving going on in any of these examples.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, SG saves both a gif thumbnail and a js_html output to embed in the docs.

@tacaswell

Copy link
Copy Markdown
Member

I'm working on sorting out what is going on with the history here.

oscargus and others added 2 commits December 21, 2022 17:11
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@tacaswell
tacaswell force-pushed the animationdeprecations branch from acf484c to d483a96 Compare December 21, 2022 22:12
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@tacaswell

Copy link
Copy Markdown
Member

I think what happened is I had rebased and force-pushed, then Oscar merged that back into his branch and then added some more changes on top.

I started from just before the merge and then cherry-picked the exrta commits on top and force-pushed again.

@oscargus

Copy link
Copy Markdown
Member Author

Yes, there was a bit of a hassle with commits, especially since I've been using two different computers. Have to learn how to deal with that in a better way...

(The main "issue" is that there will be a lot of intermediate conflicts while rebasing although the final diff will not have any conflicts...)

Just need to sort out the doc failure then. (And possibly use privatize_attribute? I seem to recall that it was used at some stage...)

@oscargus

Copy link
Copy Markdown
Member Author

Tried to fix the doc-failure by updating missing references. Seems to make sense since this became a problem for a deprecated attribute that will go away soon anyway. (And it removes a few hundred lines from this file.)

@oscargus oscargus added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Dec 27, 2022
@greglucas
greglucas merged commit c9fc6a3 into matplotlib:main Dec 29, 2022
@oscargus
oscargus deleted the animationdeprecations branch December 31, 2022 09:57
@tacaswell

Copy link
Copy Markdown
Member

(The main "issue" is that there will be a lot of intermediate conflicts while rebasing although the final diff will not have any conflicts...)

One trick I use (particuarly if I do not super care about the history or am willing to re-create it later) is to squash everything to one commit and then rebase.

)
if self._save_count is None and cache_frame_data:
_api.warn_external(
f"{frames=!r} which we can infer the length of, "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this supposed to say "which we cannot infer the length of"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API: changes Changes to the public API, typically requiring deprecation. Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: animation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants