diff --git a/0001-FIX-Pillow-asarray-bug.patch b/0001-FIX-Pillow-asarray-bug.patch new file mode 100644 index 0000000..8049ee4 --- /dev/null +++ b/0001-FIX-Pillow-asarray-bug.patch @@ -0,0 +1,22 @@ +From 5a4f6f035339d3573aa7b1a0ba67dfd4efb8f568 Mon Sep 17 00:00:00 2001 +From: Jody Klymak +Date: Thu, 1 Jul 2021 22:10:10 -0700 +Subject: [PATCH] FIX: PILLOW asarray bug + +--- + lib/matplotlib/image.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py +index a59499cd966..b2c9c4b22f9 100644 +--- a/lib/matplotlib/image.py ++++ b/lib/matplotlib/image.py +@@ -1688,7 +1688,7 @@ def _pil_png_to_float_array(pil_png): + mode = pil_png.mode + rawmode = pil_png.png.im_rawmode + if rawmode == "1": # Grayscale. +- return np.asarray(pil_png, np.float32) ++ return np.asarray(pil_png).astype(np.float32) + if rawmode == "L;2": # Grayscale. + return np.divide(pil_png, 2**2 - 1, dtype=np.float32) + if rawmode == "L;4": # Grayscale. diff --git a/0002-Dont-modify-arrays-when-masking-values-for-log.patch b/0002-Dont-modify-arrays-when-masking-values-for-log.patch new file mode 100644 index 0000000..4f5dd86 --- /dev/null +++ b/0002-Dont-modify-arrays-when-masking-values-for-log.patch @@ -0,0 +1,71 @@ +From 48eef460e8c861321e6d6a08a86ef0e45a863b59 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Thu, 24 Jun 2021 04:11:39 -0400 +Subject: [PATCH] Don't modify arrays when masking values for log. + +NumPy 1.21.0 fixed a bug with `np.ma.masked_where` where `copy=False` +now modifies the input if it is masked, which we do not want to do. +`np.ma.array` defaults to not copying the data, but copies the mask +(adding the new mask), which is what we wanted with `copy=False`. +--- + lib/matplotlib/colors.py | 4 ++-- + lib/matplotlib/tests/test_image.py | 28 ++++++++++++++++++++++++++++ + 2 files changed, 30 insertions(+), 2 deletions(-) + +diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py +index e0c42c5b69d5..0f6bf35dc440 100644 +--- a/lib/matplotlib/colors.py ++++ b/lib/matplotlib/colors.py +@@ -1545,11 +1545,11 @@ class LogNorm(Normalize): + + def autoscale(self, A): + # docstring inherited. +- super().autoscale(np.ma.masked_less_equal(A, 0, copy=False)) ++ super().autoscale(np.ma.array(A, mask=(A <= 0))) + + def autoscale_None(self, A): + # docstring inherited. +- super().autoscale_None(np.ma.masked_less_equal(A, 0, copy=False)) ++ super().autoscale_None(np.ma.array(A, mask=(A <= 0))) + + + @_make_norm_from_scale( +diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py +index 42ed7479ae54..0e385ba7a805 100644 +--- a/lib/matplotlib/tests/test_image.py ++++ b/lib/matplotlib/tests/test_image.py +@@ -1233,6 +1233,34 @@ def test_imshow_quantitynd(): + fig.canvas.draw() + + ++@check_figures_equal(extensions=['png']) ++def test_norm_change(fig_test, fig_ref): ++ # LogNorm should not mask anything invalid permanently. ++ data = np.full((5, 5), 1, dtype=np.float64) ++ data[0:2, :] = -1 ++ ++ masked_data = np.ma.array(data, mask=False) ++ masked_data.mask[0:2, 0:2] = True ++ ++ cmap = plt.get_cmap('viridis').with_extremes(under='w') ++ ++ ax = fig_test.subplots() ++ im = ax.imshow(data, norm=colors.LogNorm(vmin=0.5, vmax=1), ++ extent=(0, 5, 0, 5), interpolation='nearest', cmap=cmap) ++ im.set_norm(colors.Normalize(vmin=-2, vmax=2)) ++ im = ax.imshow(masked_data, norm=colors.LogNorm(vmin=0.5, vmax=1), ++ extent=(5, 10, 5, 10), interpolation='nearest', cmap=cmap) ++ im.set_norm(colors.Normalize(vmin=-2, vmax=2)) ++ ax.set(xlim=(0, 10), ylim=(0, 10)) ++ ++ ax = fig_ref.subplots() ++ ax.imshow(data, norm=colors.Normalize(vmin=-2, vmax=2), ++ extent=(0, 5, 0, 5), interpolation='nearest', cmap=cmap) ++ ax.imshow(masked_data, norm=colors.Normalize(vmin=-2, vmax=2), ++ extent=(5, 10, 5, 10), interpolation='nearest', cmap=cmap) ++ ax.set(xlim=(0, 10), ylim=(0, 10)) ++ ++ + @check_figures_equal(extensions=['png']) + def test_huge_range_log(fig_test, fig_ref): + data = np.full((5, 5), -1, dtype=np.float64) diff --git a/python-matplotlib.changes b/python-matplotlib.changes index 0f63ebd..a0ca064 100644 --- a/python-matplotlib.changes +++ b/python-matplotlib.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Wed Jul 7 10:02:08 UTC 2021 - Antonio Larrosa + +- Add patches from upstream to fix an raised exception saying + "__array__(): takes 1 positional argument but 2 were given" + and an incompatibility with numpy 1.21.0 (slightly rebased): + * 0001-FIX-Pillow-asarray-bug.patch + * 0002-Dont-modify-arrays-when-masking-values-for-log.patch + ------------------------------------------------------------------- Fri May 14 01:34:50 UTC 2021 - Arun Persaud diff --git a/python-matplotlib.spec b/python-matplotlib.spec index 99acc2e..3d1a8f0 100644 --- a/python-matplotlib.spec +++ b/python-matplotlib.spec @@ -1,5 +1,5 @@ # -# spec file for package python-matplotlib-test +# spec file for package python-matplotlib # # Copyright (c) 2021 SUSE LLC # @@ -41,6 +41,10 @@ Source1: matplotlib-setup.cfg # Bundled version of freetype and qhull for testing purposes only Source98: http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz Source99: https://downloads.sourceforge.net/project/freetype/freetype2/2.6.1/freetype-2.6.1.tar.gz +# PATCH-FIX-UPSTREAM 0001-FIX-Pillow-asarray-bug.patch - Fix from upstream for an error related to asarray +Patch0: 0001-FIX-Pillow-asarray-bug.patch +# PATCH-FIX-UPSTREAM 0002-Dont-modify-arrays-when-masking-values-for-log.patch - Fix from upstream for numpy 1.21.0 +Patch1: 0002-Dont-modify-arrays-when-masking-values-for-log.patch BuildRequires: %{python_module Cycler >= 0.10} BuildRequires: %{python_module devel} BuildRequires: %{python_module kiwisolver >= 1.0.1} @@ -245,6 +249,8 @@ for %{name} plotting package %prep %setup -q -n matplotlib-%{version} +%patch0 -p1 +%patch1 -p1 #copy freetype to the right location, so that matplotlib will not try to download it mkdir -p ~/.cache/matplotlib/ SHA=($(sha256sum %{SOURCE98}))