8000 Deprecate JPEG-specific kwargs and rcParams to savefig. by anntzer · Pull Request #16231 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deprecate JPEG-specific kwargs and rcParams to savefig. #16231

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 2 commits into from
Mar 11, 2020

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Jan 15, 2020

Saving Matplotlib figures to jpeg is generally not a great idea to start
with (even at the default quality of 95 there are visible (faint)
artefacts around sharp lines, and at quality=95 the files produced are
bigger than the corresponding pngs anyways).

We don't need to completely get rid of jpeg support, but we can at least
simplify the code path (which otherwise also needs to be duplicated in
mplcairo) and not have to document these jpeg-specific kwargs (in two
places!). Note that users can still set them via pil_kwargs.

The changes to _delete_parameter are so that we can write

@_delete_parameter(..., "foo")
def f(**kwargs): ...

where foo actually only shows up in kwargs.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 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

@anntzer anntzer added this to the v3.3.0 milestone Jan 15, 2020
@anntzer anntzer force-pushed the jpegkwargs branch 2 times, most recently from 615d649 to bfd3005 Compare January 15, 2020 17:39
@anntzer anntzer force-pushed the jpegkwargs branch 2 times, most recently from 6dfdb97 to c06dbda Compare February 11, 2020 21:43
Copy link
Member
@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

_delete_parameter is quite intricate, even more so with the added kwargs handling. Please try to be as clear as possible in the documentation and implementation.

Note: This part is actually the one which held me from reviewing for a while. Maybe it would have helped a bit if it was it's own PR. Even though the jpg deprecation would still be dependent on it, the change to _delete_parameter would have been a smaller PR, which might have been a psychological advantage for the motivation to review.


signature = inspect.signature(func)
assert name in signature.parameters, (
kw_name = next((param.name for param in signature.parameters.values()
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
kw_name = next((param.name for param in signature.parameters.values()
# name of kwargs parameter, e.g. 'kwargs' if **kwargs is in the signature of the
# decorated function, or None if the function does not have such a parameter
kwargs_name = next((param.name for param in signature.parameters.values()

Even though this may seem picky, this is rather unusual code and every bit of clarity helps (connection kwargs <-> kwargs_name).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -307,7 +307,7 @@ def __repr__(self):
_deprecated_parameter = _deprecated_parameter_class()


def _delete_parameter(since, name, func=None):
def _delete_parameter(since, name, func=None, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

I would explicitly mention in the docstring:

This can also be used for parameters that are handled through **kwargs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done (just below)

addendum = (
f"If any parameter follows {name!r}, they should be passed as "
f"keyword, not positionally.")
if kwargs.get("addendum"):
Copy link
Member

Choose a reason for hiding this comment

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

AFAICS this is a new optional parameter of _delete_parameter. Please make it explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I now mentioned that all additional parameters are forwarded to warn_deprecated.

@anntzer anntzer force-pushed the jpegkwargs branch 2 times, most recently from a09585a to 84cf1e2 Compare February 11, 2020 22:05
Copy link
Member
@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Conditional on CI. Would very much love some explicit tests on _delete_parameter.

@anntzer
Copy link
Contributor Author
anntzer commented Feb 11, 2020

I agree it's not so nice to bundle the changes to _delete_parameter here, but OTOH, my experience tells me that if I made them as a separate PR with no intended use case, it would have taken forever to get it reviewed...

@timhoffm
Copy link
Member

my experience tells me that if I made them as a separate PR with no intended use case, it would have taken forever to get it reviewed...

Just speaking from my point of view: I'd been more inclined to review this separately. You could have explained the need in a short sentence and immediately created the second PR with "waiting for other PR" tagged. Yes, sometimes PR take a long time, in particular if they are involved. But I dispute that embedding them in another PR speeds up review (compared to a PR that indicates the context as proposed).

@anntzer
Copy link
Contributor Author
anntzer commented Feb 11, 2020

Thanks for your suggestion (which I do value a lot, given that you are a reviewer on most of my PRs so I do want to keep you happy :))

@anntzer
Copy link
Contributor Author
anntzer commented Feb 11, 2020

added tests for delete_parameter (as a separate commit)

@anntzer
Copy link
Contributor Author
anntzer commented Mar 10, 2020

rebased

@anntzer anntzer mentioned this pull request Mar 10, 2020
6 tasks
Copy link
Member
@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

You have too many deprecation PRs open...

@timhoffm
Copy link
Member

@anntzer I propose you rebase and self-merge deprecation PRs once they got two approvals. Otherwise, we'll be boundcing back and forth with "Needs rebase" tags.

anntzer added 2 commits March 11, 2020 10:50
Saving Matplotlib figures to jpeg is generally not a great idea to start
with (even at the default quality of 95 there are visible (faint)
artefacts around sharp lines, and at quality=95 the files produced are
bigger than the corresponding pngs anyways).

We don't need to completely get rid of jpeg support, but we can at least
simplify the code path (which otherwise also needs to be duplicated in
mplcairo) and not have to document these jpeg-specific kwargs (in two
places!).  Note that users can still set them via `pil_kwargs`.

The changes to _delete_parameter are so that we can write
```
@_delete_parameter(..., "foo")
def f(**kwargs): ...
```
where `foo` actually only shows up in `kwargs`.
@anntzer
Copy link
Contributor Author
anntzer commented Mar 11, 2020

Sure, I'll do that.
I guess you can just review as "can self-merge"?

@anntzer anntzer merged commit 623851f into matplotlib:master Mar 11, 2020
@anntzer anntzer deleted the jpegkwargs branch March 11, 2020 10:52
< 6D40 div > @anntzer anntzer mentioned this pull request Mar 11, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0