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

Clarify how to use keyword arguments in FuncAnimation #24139

Closed
wants to merge 1 commit into from

Conversation

oscargus
Copy link
Contributor

@oscargus oscargus commented Oct 11, 2022

PR Summary

Closes #20326

I didn't find a good animation example to modify...

PR Checklist

Tests and Styling

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

Documentation

  • New features are documented, with examples if plot related.
  • 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).

@@ -1564,6 +1565,14 @@ def init_func() -> iterable_of_artists
fargs : tuple or None, optional
Additional arguments to pass to each call to *func*.

An option to *fargs* is to use `functools.partial`, with the added
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
An option to *fargs* is to use `functools.partial`, with the added
An alternative to *fargs* is to use `functools.partial`, with the added

Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

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

stealing some of the language/constructs from #20358 to make it clearer that partial is an alternative to fargs

Comment on lines +1521 to +1522
arguments can be supplied via the *fargs* parameter. See *fargs* for
how to use `functools.partial` to supply keyword arguments.
Copy link
Member

@story645 story645 Oct 12, 2022

Choose a reason for hiding this comment

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

Suggested change
arguments can be supplied via the *fargs* parameter. See *fargs* for
how to use `functools.partial` to supply keyword arguments.
arguments can be supplied using `functools.partial` or via the *fargs* parameter.

Flipped because I think the functools version is preferred. I think it's gonna be clearer to add the information about partial in this section since it's passed in as the func keyword, Maybe after the required signature, something like:

To pass in a function with positional keywords, set func to the partial function::
      
     func = partial(func, frame, **kwargs)

Comment on lines +1568 to +1575
An option to *fargs* is to use `functools.partial`, with the added
benefit of also supporting keyword arguments. An example is to pass
something like::

partial(func, **kwargs)

as *func*.

Copy link
Member

@story645 story645 Oct 12, 2022

Choose a reason for hiding this comment

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

I think if you move the intro of partial up to func, this can be simplified to

Suggested change
An option to *fargs* is to use `functools.partial`, with the added
benefit of also supporting keyword arguments. An example is to pass
something like::
partial(func, **kwargs)
as *func*.
Passing in `functools.partial` as *func* is preferred to passing in *fargs* and supports keyword arguments. See *func* for an example.

benefit of also supporting keyword arguments. An example is to pass
something like::

partial(func, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't you normally have the case that you want to set some kwargs explicitly? Then I suggest to make the example more concrete:

Suggested change
partial(func, **kwargs)
partial(func, my_kwarg='something')

Maye even show a more complete FuncAnimation call to show this fits in.

@oscargus
Copy link
Contributor Author

There is also #20358 which solves the same issue. I'll have a look and may go for extending that instead (the importance of linking PRs to issues...).

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.

FuncAnimation Named Arguments
4 participants