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

Appearance settings

Commit 1e12cad

Browse filesBrowse files
timhoffmanntzer
authored andcommitted
Deprecate imread() reading from URLs
1 parent 408b1ab commit 1e12cad
Copy full SHA for 1e12cad

File tree

Expand file treeCollapse file tree

3 files changed

+17
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-4
lines changed
+5Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,9 @@ 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 before reading using
1435+
``urllib.request.urlopen()``.
14331436
format : str, optional
14341437
The image file format assumed for reading the data. If not
14351438
given, the format is deduced from the filename. If nothing can
@@ -1472,9 +1475,12 @@ def imread(fname, format=None):
14721475
img_open = (
14731476
PIL.PngImagePlugin.PngImageFile if ext == 'png' else PIL.Image.open)
14741477
if isinstance(fname, str):
1475-
14761478
parsed = parse.urlparse(fname)
14771479
if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly.
1480+
cbook.warn_deprecated(
1481+
"3.4", message="Directly reading images from URLs is "
1482+
"deprecated. Please open the URL before "
1483+
"reading using urllib.request.urlopen().")
14781484
# hide imports to speed initial import on systems with slow linkers
14791485
from urllib import request
14801486
ssl_ctx = mpl._get_ssl_context()

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from PIL import Image
1313

1414
from matplotlib import (
15-
colors, image as mimage, patches, pyplot as plt, style, rcParams)
15+
_api, colors, image as mimage, patches, pyplot as plt, style, rcParams)
1616
from matplotlib.image import (AxesImage, BboxImage, FigureImage,
1717
NonUniformImage, PcolorImage)
1818
from matplotlib.testing.decorators import check_figures_equal, image_comparison
@@ -714,7 +714,8 @@ def test_load_from_url():
714714
url = ('file:'
715715
+ ('///' if sys.platform == 'win32' else '')
716716
+ path.resolve().as_posix())
717-
plt.imread(url)
717+
with _api.suppress_matplotlib_deprecation_warning():
718+
plt.imread(url)
718719
with urllib.request.urlopen(url) as file:
719720
plt.imread(file)
720721

@@ -1128,7 +1129,8 @@ def test_exact_vmin():
11281129
@pytest.mark.network
11291130
@pytest.mark.flaky
11301131
def test_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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.