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

Commitdbe3622

Browse files
authored
Merge pull request#19367 from anntzer/deprecate-imread-url
Deprecate imread() reading from URLs
2 parents476b7e4 +9302392 commitdbe3622

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``imread()`` reading from URLs
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Passing a URL to `~.pyplot.imread()` is deprecated. Please open the URL for
5+
reading and directly use the Pillow API
6+
(``PIL.Image.open(urllib.request.urlopen(url))``, or
7+
``PIL.Image.open(io.BytesIO(requests.get(url).content))``) instead.

‎lib/matplotlib/image.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,10 @@ def imread(fname, format=None):
14301430
fname : str or file-like
14311431
The image file to read: a filename, a URL or a file-like object opened
14321432
in read-binary mode.
1433+
1434+
Passing a URL is deprecated. Please open the URL
1435+
for reading and pass the result to Pillow, e.g. with
1436+
``PIL.Image.open(urllib.request.urlopen(url))``.
14331437
format : str, optional
14341438
The image file format assumed for reading the data. If not
14351439
given, the format is deduced from the filename. If nothing can
@@ -1472,9 +1476,13 @@ def imread(fname, format=None):
14721476
img_open= (
14731477
PIL.PngImagePlugin.PngImageFileifext=='png'elsePIL.Image.open)
14741478
ifisinstance(fname,str):
1475-
14761479
parsed=parse.urlparse(fname)
14771480
iflen(parsed.scheme)>1:# Pillow doesn't handle URLs directly.
1481+
cbook.warn_deprecated(
1482+
"3.4",message="Directly reading images from URLs is "
1483+
"deprecated. Please open the URL for reading and pass the "
1484+
"result to Pillow, e.g. with "
1485+
"``PIL.Image.open(urllib.request.urlopen(url))``.")
14781486
# hide imports to speed initial import on systems with slow linkers
14791487
fromurllibimportrequest
14801488
ssl_ctx=mpl._get_ssl_context()

‎lib/matplotlib/tests/test_image.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
fromPILimportImage
1313

1414
frommatplotlibimport (
15-
colors,imageasmimage,patches,pyplotasplt,style,rcParams)
15+
_api,colors,imageasmimage,patches,pyplotasplt,style,rcParams)
1616
frommatplotlib.imageimport (AxesImage,BboxImage,FigureImage,
1717
NonUniformImage,PcolorImage)
1818
frommatplotlib.testing.decoratorsimportcheck_figures_equal,image_comparison
@@ -714,7 +714,8 @@ def test_load_from_url():
714714
url= ('file:'
715715
+ ('///'ifsys.platform=='win32'else'')
716716
+path.resolve().as_posix())
717-
plt.imread(url)
717+
with_api.suppress_matplotlib_deprecation_warning():
718+
plt.imread(url)
718719
withurllib.request.urlopen(url)asfile:
719720
plt.imread(file)
720721

@@ -1128,7 +1129,8 @@ def test_exact_vmin():
11281129
@pytest.mark.network
11291130
@pytest.mark.flaky
11301131
deftest_https_imread_smoketest():
1131-
v=mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')
1132+
with_api.suppress_matplotlib_deprecation_warning():
1133+
v=mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')
11321134

11331135

11341136
# A basic ndarray subclass that implements a quantity

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp