Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix image fmt detection for Path input. #10754

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
Mar 12, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 12, 2018

PR Summary

Fixes #10753. Should probably go to 2.2.1 as the feature is basically unusable without the fix.

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

@anntzer anntzer added this to the v2.2.1 milestone Mar 12, 2018
@anntzer anntzer force-pushed the pathlib-default-fmt branch from ce2b1fd to 19d4e8c Compare March 12, 2018 00:15
@@ -1,6 +1,4 @@
from __future__ import absolute_import, division, print_function
Copy link
Member

Choose a reason for hiding this comment

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

If you're backporting, you don't want to remove this.

@anntzer anntzer force-pushed the pathlib-default-fmt branch from 19d4e8c to 8605b35 Compare March 12, 2018 01:22
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -2130,6 +2130,8 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,

if format is None:
# get format from filename, or from backend's default filetype
if isinstance(filename, getattr(os, "PathLike", ())):
Copy link
Member

Choose a reason for hiding this comment

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

Am I correct, that this will only fix the format detection for Python 3.6+? Since this will probably go into 2.2.x. it should also hande pre-python3.6 Path objects, i.e. check for Path instance and use filename = str(filename)?

Copy link
Member

Choose a reason for hiding this comment

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

Also PEP-519 states

Libraries wishing to support path objects and a version of Python prior to Python 3.6 and the existence of os.fspath() can use the idiom of path.__fspath__() if hasattr(path, "__fspath__") else path.

But that's more a matter of taste.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original PR explicitly only supported 3.6+ (see whatsnew note in https://github.com/matplotlib/matplotlib/pull/10231/files). I have no intent to reimplement the pathlike API on <3.6.

So I'll leave things as they are.

@jklymak jklymak merged commit 24d530e into matplotlib:master Mar 12, 2018
@anntzer anntzer deleted the pathlib-default-fmt branch March 12, 2018 19:43
QuLogic added a commit that referenced this pull request Mar 12, 2018
@anntzer anntzer mentioned this pull request Jul 27, 2018
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.

PDF saved as raster graphic when plt.savefig is given a Path object
5 participants