From 22657e814729857b05b75b9f40e1b2d32f6e60d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Sok=C3=B3=C5=82?= Date: Fri, 4 Aug 2023 12:34:51 +0200 Subject: [PATCH 1/2] ENH: Update numpy exceptions imports --- lib/matplotlib/cbook.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 72ecdfd19cea..8568d3e7e987 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -21,8 +21,14 @@ import types import weakref +from packaging.version import parse as parse_version import numpy as np +if parse_version(np.__version__) >= parse_version("1.25.0"): + from numpy.exceptions import VisibleDeprecationWarning +else: + from numpy import VisibleDeprecationWarning + import matplotlib from matplotlib import _api, _c_internal_utils @@ -1064,7 +1070,7 @@ def _combine_masks(*args): raise ValueError("Masked arrays must be 1-D") try: x = np.asanyarray(x) - except (np.VisibleDeprecationWarning, ValueError): + except (VisibleDeprecationWarning, ValueError): # NumPy 1.19 raises a warning about ragged arrays, but we want # to accept basically anything here. x = np.asanyarray(x, dtype=object) @@ -1658,7 +1664,7 @@ def index_of(y): pass try: y = _check_1d(y) - except (np.VisibleDeprecationWarning, ValueError): + except (VisibleDeprecationWarning, ValueError): # NumPy 1.19 will warn on ragged input, and we can't actually use it. pass else: From ec3213b140c45cef155b1ef9be95fcfb78037afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Sok=C3=B3=C5=82?= Date: Fri, 4 Aug 2023 14:06:50 +0200 Subject: [PATCH 2/2] ENH: Make import selection implicit --- lib/matplotlib/cbook.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 8568d3e7e987..bea97102006b 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -21,12 +21,11 @@ import types import weakref -from packaging.version import parse as parse_version import numpy as np -if parse_version(np.__version__) >= parse_version("1.25.0"): - from numpy.exceptions import VisibleDeprecationWarning -else: +try: + from numpy.exceptions import VisibleDeprecationWarning # numpy >= 1.25 +except ImportError: from numpy import VisibleDeprecationWarning import matplotlib