Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Deprecate imread() reading from URLs#19367

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 2 commits intomatplotlib:masterfromanntzer:deprecate-imread-url
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionsdoc/api/next_api_changes/deprecations/18649-TH.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
``imread()`` reading from URLs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Passing a URL to `~.pyplot.imread()` is deprecated. Please open the URL for
reading and directly use the Pillow API
(``PIL.Image.open(urllib.request.urlopen(url))``, or
``PIL.Image.open(io.BytesIO(requests.get(url).content))``) instead.
10 changes: 9 additions & 1 deletionlib/matplotlib/image.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1430,6 +1430,10 @@ def imread(fname, format=None):
fname : str or file-like
The image file to read: a filename, a URL or a file-like object opened
in read-binary mode.

Passing a URL is deprecated. Please open the URL
for reading and pass the result to Pillow, e.g. with
``PIL.Image.open(urllib.request.urlopen(url))``.
format : str, optional
The image file format assumed for reading the data. If not
given, the format is deduced from the filename. If nothing can
Expand DownExpand Up@@ -1472,9 +1476,13 @@ def imread(fname, format=None):
img_open = (
PIL.PngImagePlugin.PngImageFile if ext == 'png' else PIL.Image.open)
if isinstance(fname, str):

parsed = parse.urlparse(fname)
if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly.
cbook.warn_deprecated(
"3.4", message="Directly reading images from URLs is "
"deprecated. Please open the URL for reading and pass the "
"result to Pillow, e.g. with "
"``PIL.Image.open(urllib.request.urlopen(url))``.")
# hide imports to speed initial import on systems with slow linkers
from urllib import request
ssl_ctx = mpl._get_ssl_context()
Expand Down
8 changes: 5 additions & 3 deletionslib/matplotlib/tests/test_image.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@
from PIL import Image

from matplotlib import (
colors, image as mimage, patches, pyplot as plt, style, rcParams)
_api,colors, image as mimage, patches, pyplot as plt, style, rcParams)
from matplotlib.image import (AxesImage, BboxImage, FigureImage,
NonUniformImage, PcolorImage)
from matplotlib.testing.decorators import check_figures_equal, image_comparison
Expand DownExpand Up@@ -714,7 +714,8 @@ def test_load_from_url():
url = ('file:'
+ ('///' if sys.platform == 'win32' else '')
+ path.resolve().as_posix())
plt.imread(url)
with _api.suppress_matplotlib_deprecation_warning():
plt.imread(url)
with urllib.request.urlopen(url) as file:
plt.imread(file)

Expand DownExpand Up@@ -1128,7 +1129,8 @@ def test_exact_vmin():
@pytest.mark.network
@pytest.mark.flaky
def test_https_imread_smoketest():
v = mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')
with _api.suppress_matplotlib_deprecation_warning():
v = mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you properly fix this?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The point is that after the removal, reading this just won't involve matplotlib at all (it'll bePIL.Image.open(urllib.request.urlopen(...)), so the whole test will go away.

Copy link
Member

Choose a reason for hiding this comment

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

oops sorry - I missed what the test was for....



# A basic ndarray subclass that implements a quantity
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp