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

Commit5b132aa

Browse files
committed
Deprecate imread() reading from URLs
1 parent825f518 commit5b132aa

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``imread()`` reading from URLs
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Passing a URL to `~.pyplot.imread()` is deprecated. Please open the URL before
5+
reading using ``urllib.request.urlopen()``.

‎lib/matplotlib/image.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,9 @@ def imread(fname, format=None):
14311431
fname : str or file-like
14321432
The image file to read: a filename, a URL or a file-like object opened
14331433
in read-binary mode.
1434+
1435+
Passing a URL is deprecated. Please open the URL before reading using
1436+
``urllib.request.urlopen()``.
14341437
format : str, optional
14351438
The image file format assumed for reading the data. If not
14361439
given, the format is deduced from the filename. If nothing can
@@ -1473,9 +1476,12 @@ def imread(fname, format=None):
14731476
img_open= (
14741477
PIL.PngImagePlugin.PngImageFileifext=='png'elsePIL.Image.open)
14751478
ifisinstance(fname,str):
1476-
14771479
parsed=parse.urlparse(fname)
14781480
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 before "
1484+
"reading using urllib.request.urlopen().")
14791485
# hide imports to speed initial import on systems with slow linkers
14801486
fromurllibimportrequest
14811487
withrequest.urlopen(fname,

‎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+
cbook,colors,imageasmimage,patches,pyplotasplt,style,rcParams)
1616
frommatplotlib.imageimport (AxesImage,BboxImage,FigureImage,
1717
NonUniformImage,PcolorImage)
1818
frommatplotlib.testing.decoratorsimportcheck_figures_equal,image_comparison
@@ -705,7 +705,8 @@ def test_load_from_url():
705705
url= ('file:'
706706
+ ('///'ifsys.platform=='win32'else'')
707707
+path.resolve().as_posix())
708-
plt.imread(url)
708+
withcbook._suppress_matplotlib_deprecation_warning():
709+
plt.imread(url)
709710
plt.imread(urllib.request.urlopen(url))
710711

711712

@@ -1124,7 +1125,8 @@ def test_exact_vmin():
11241125
@pytest.mark.network
11251126
@pytest.mark.flaky
11261127
deftest_https_imread_smoketest():
1127-
v=mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')
1128+
withcbook._suppress_matplotlib_deprecation_warning():
1129+
v=mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')
11281130

11291131

11301132
# A basic ndarray subclass that implements a quantity

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp