diff --git a/lib/matplotlib/pylab.py b/lib/matplotlib/pylab.py index 77eb6506d87f..a50779cf6d26 100644 --- a/lib/matplotlib/pylab.py +++ b/lib/matplotlib/pylab.py @@ -60,6 +60,8 @@ bytes = __import__("builtins").bytes # We also don't want the numpy version of these functions abs = __import__("builtins").abs +bool = __import__("builtins").bool max = __import__("builtins").max min = __import__("builtins").min +pow = __import__("builtins").pow round = __import__("builtins").round diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 5cafcdb5d2e9..530fddf127a8 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5743,7 +5743,12 @@ def test_text_labelsize(): ax.tick_params(direction='out') -@image_comparison(['pie_default.png']) +# Note: The `pie` image tests were affected by Numpy 2.0 changing promotions +# (NEP 50). While the changes were only marginal, tolerances were introduced. +# These tolerances could likely go away when numpy 2.0 is the minimum supported +# numpy and the images are regenerated. + +@image_comparison(['pie_default.png'], tol=0.01) def test_pie_default(): # The slices will be ordered and plotted counter-clockwise. labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' @@ -5756,7 +5761,7 @@ def test_pie_default(): @image_comparison(['pie_linewidth_0', 'pie_linewidth_0', 'pie_linewidth_0'], - extensions=['png'], style='mpl20') + extensions=['png'], style='mpl20', tol=0.01) def test_pie_linewidth_0(): # The slices will be ordered and plotted counter-clockwise. labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' @@ -5788,7 +5793,7 @@ def test_pie_linewidth_0(): plt.axis('equal') -@image_comparison(['pie_center_radius.png'], style='mpl20') +@image_comparison(['pie_center_radius.png'], style='mpl20', tol=0.005) def test_pie_center_radius(): # The slices will be ordered and plotted counter-clockwise. labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' @@ -5808,7 +5813,7 @@ def test_pie_center_radius(): plt.axis('equal') -@image_comparison(['pie_linewidth_2.png'], style='mpl20') +@image_comparison(['pie_linewidth_2.png'], style='mpl20', tol=0.01) def test_pie_linewidth_2(): # The slices will be ordered and plotted counter-clockwise. labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' @@ -5823,7 +5828,7 @@ def test_pie_linewidth_2(): plt.axis('equal') -@image_comparison(['pie_ccw_true.png'], style='mpl20') +@image_comparison(['pie_ccw_true.png'], style='mpl20', tol=0.01) def test_pie_ccw_true(): # The slices will be ordered and plotted counter-clockwise. labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' @@ -5838,7 +5843,7 @@ def test_pie_ccw_true(): plt.axis('equal') -@image_comparison(['pie_frame_grid.png'], style='mpl20') +@image_comparison(['pie_frame_grid.png'], style='mpl20', tol=0.002) def test_pie_frame_grid(): # The slices will be ordered and plotted counter-clockwise. labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' @@ -5865,7 +5870,7 @@ def test_pie_frame_grid(): plt.axis('equal') -@image_comparison(['pie_rotatelabels_true.png'], style='mpl20') +@image_comparison(['pie_rotatelabels_true.png'], style='mpl20', tol=0.009) def test_pie_rotatelabels_true(): # The slices will be ordered and plotted counter-clockwise. labels = 'Hogwarts', 'Frogs', 'Dogs', 'Logs' @@ -5880,7 +5885,7 @@ def test_pie_rotatelabels_true(): plt.axis('equal') -@image_comparison(['pie_no_label.png']) +@image_comparison(['pie_no_label.png'], tol=0.01) def test_pie_nolabel_but_legend(): labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' sizes = [15, 30, 45, 10] @@ -5894,7 +5899,7 @@ def test_pie_nolabel_but_legend(): plt.legend() -@image_comparison(['pie_shadow.png'], style='mpl20') +@image_comparison(['pie_shadow.png'], style='mpl20', tol=0.002) def test_pie_shadow(): # Also acts as a test for the shade argument of Shadow sizes = [15, 30, 45, 10] diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index d77077340e8c..30cd5dfa844b 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -1379,38 +1379,38 @@ def test_scalarmappable_to_rgba(bytes): # uint8 RGBA x = np.ones((2, 3, 4), dtype=np.uint8) expected = x.copy() if bytes else x.astype(np.float32)/255 - np.testing.assert_array_equal(sm.to_rgba(x, bytes=bytes), expected) + np.testing.assert_almost_equal(sm.to_rgba(x, bytes=bytes), expected) # uint8 RGB expected[..., 3] = alpha_1 - np.testing.assert_array_equal(sm.to_rgba(x[..., :3], bytes=bytes), expected) + np.testing.assert_almost_equal(sm.to_rgba(x[..., :3], bytes=bytes), expected) # uint8 masked RGBA xm = np.ma.masked_array(x, mask=np.zeros_like(x)) xm.mask[0, 0, 0] = True expected = x.copy() if bytes else x.astype(np.float32)/255 expected[0, 0, 3] = 0 - np.testing.assert_array_equal(sm.to_rgba(xm, bytes=bytes), expected) + np.testing.assert_almost_equal(sm.to_rgba(xm, bytes=bytes), expected) # uint8 masked RGB expected[..., 3] = alpha_1 expected[0, 0, 3] = 0 - np.testing.assert_array_equal(sm.to_rgba(xm[..., :3], bytes=bytes), expected) + np.testing.assert_almost_equal(sm.to_rgba(xm[..., :3], bytes=bytes), expected) # float RGBA x = np.ones((2, 3, 4), dtype=float) * 0.5 expected = (x * 255).astype(np.uint8) if bytes else x.copy() - np.testing.assert_array_equal(sm.to_rgba(x, bytes=bytes), expected) + np.testing.assert_almost_equal(sm.to_rgba(x, bytes=bytes), expected) # float RGB expected[..., 3] = alpha_1 - np.testing.assert_array_equal(sm.to_rgba(x[..., :3], bytes=bytes), expected) + np.testing.assert_almost_equal(sm.to_rgba(x[..., :3], bytes=bytes), expected) # float masked RGBA xm = np.ma.masked_array(x, mask=np.zeros_like(x)) xm.mask[0, 0, 0] = True expected = (x * 255).astype(np.uint8) if bytes else x.copy() expected[0, 0, 3] = 0 - np.testing.assert_array_equal(sm.to_rgba(xm, bytes=bytes), expected) + np.testing.assert_almost_equal(sm.to_rgba(xm, bytes=bytes), expected) # float masked RGB expected[..., 3] = alpha_1 expected[0, 0, 3] = 0 - np.testing.assert_array_equal(sm.to_rgba(xm[..., :3], bytes=bytes), expected) + np.testing.assert_almost_equal(sm.to_rgba(xm[..., :3], bytes=bytes), expected) def test_failed_conversions():