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 6089283

Browse filesBrowse files
committed
Fix Numpy 2.0 related test failures
1 parent c447b60 commit 6089283
Copy full SHA for 6089283

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+24
-17
lines changed

‎lib/matplotlib/pylab.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pylab.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
bytes = __import__("builtins").bytes
6161
# We also don't want the numpy version of these functions
6262
abs = __import__("builtins").abs
63+
bool = __import__("builtins").bool
6364
max = __import__("builtins").max
6465
min = __import__("builtins").min
66+
pow = __import__("builtins").pow
6567
round = __import__("builtins").round

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+14-9Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5743,7 +5743,12 @@ def test_text_labelsize():
57435743
ax.tick_params(direction='out')
57445744

57455745

5746-
@image_comparison(['pie_default.png'])
5746+
# Note: The `pie` image tests were affected by Numpy 2.0 changing promotions
5747+
# (NEP 50). While the changes were only marginal, tolerances were introduced.
5748+
# These tolerances could likely go away when numpy 2.0 is the minimum supported
5749+
# numpy and the images are regenerated.
5750+
5751+
@image_comparison(['pie_default.png'], tol=0.01)
57475752
def test_pie_default():
57485753
# The slices will be ordered and plotted counter-clockwise.
57495754
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
@@ -5756,7 +5761,7 @@ def test_pie_default():
57565761

57575762

57585763
@image_comparison(['pie_linewidth_0', 'pie_linewidth_0', 'pie_linewidth_0'],
5759-
extensions=['png'], style='mpl20')
5764+
extensions=['png'], style='mpl20', tol=0.01)
57605765
def test_pie_linewidth_0():
57615766
# The slices will be ordered and plotted counter-clockwise.
57625767
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
@@ -5788,7 +5793,7 @@ def test_pie_linewidth_0():
57885793
plt.axis('equal')
57895794

57905795

5791-
@image_comparison(['pie_center_radius.png'], style='mpl20')
5796+
@image_comparison(['pie_center_radius.png'], style='mpl20', tol=0.005)
57925797
def test_pie_center_radius():
57935798
# The slices will be ordered and plotted counter-clockwise.
57945799
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
@@ -5808,7 +5813,7 @@ def test_pie_center_radius():
58085813
plt.axis('equal')
58095814

58105815

5811-
@image_comparison(['pie_linewidth_2.png'], style='mpl20')
5816+
@image_comparison(['pie_linewidth_2.png'], style='mpl20', tol=0.01)
58125817
def test_pie_linewidth_2():
58135818
# The slices will be ordered and plotted counter-clockwise.
58145819
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
@@ -5823,7 +5828,7 @@ def test_pie_linewidth_2():
58235828
plt.axis('equal')
58245829

58255830

5826-
@image_comparison(['pie_ccw_true.png'], style='mpl20')
5831+
@image_comparison(['pie_ccw_true.png'], style='mpl20', tol=0.01)
58275832
def test_pie_ccw_true():
58285833
# The slices will be ordered and plotted counter-clockwise.
58295834
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
@@ -5838,7 +5843,7 @@ def test_pie_ccw_true():
58385843
plt.axis('equal')
58395844

58405845

5841-
@image_comparison(['pie_frame_grid.png'], style='mpl20')
5846+
@image_comparison(['pie_frame_grid.png'], style='mpl20', tol=0.002)
58425847
def test_pie_frame_grid():
58435848
# The slices will be ordered and plotted counter-clockwise.
58445849
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
@@ -5865,7 +5870,7 @@ def test_pie_frame_grid():
58655870
plt.axis('equal')
58665871

58675872

5868-
@image_comparison(['pie_rotatelabels_true.png'], style='mpl20')
5873+
@image_comparison(['pie_rotatelabels_true.png'], style='mpl20', tol=0.009)
58695874
def test_pie_rotatelabels_true():
58705875
# The slices will be ordered and plotted counter-clockwise.
58715876
labels = 'Hogwarts', 'Frogs', 'Dogs', 'Logs'
@@ -5880,7 +5885,7 @@ def test_pie_rotatelabels_true():
58805885
plt.axis('equal')
58815886

58825887

5883-
@image_comparison(['pie_no_label.png'])
5888+
@image_comparison(['pie_no_label.png'], tol=0.01)
58845889
def test_pie_nolabel_but_legend():
58855890
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
58865891
sizes = [15, 30, 45, 10]
@@ -5894,7 +5899,7 @@ def test_pie_nolabel_but_legend():
58945899
plt.legend()
58955900

58965901

5897-
@image_comparison(['pie_shadow.png'], style='mpl20')
5902+
@image_comparison(['pie_shadow.png'], style='mpl20', tol=0.002)
58985903
def test_pie_shadow():
58995904
# Also acts as a test for the shade argument of Shadow
59005905
sizes = [15, 30, 45, 10]

‎lib/matplotlib/tests/test_colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colors.py
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,38 +1379,38 @@ def test_scalarmappable_to_rgba(bytes):
13791379
# uint8 RGBA
13801380
x = np.ones((2, 3, 4), dtype=np.uint8)
13811381
expected = x.copy() if bytes else x.astype(np.float32)/255
1382-
np.testing.assert_array_equal(sm.to_rgba(x, bytes=bytes), expected)
1382+
np.testing.assert_almost_equal(sm.to_rgba(x, bytes=bytes), expected)
13831383
# uint8 RGB
13841384
expected[..., 3] = alpha_1
1385-
np.testing.assert_array_equal(sm.to_rgba(x[..., :3], bytes=bytes), expected)
1385+
np.testing.assert_almost_equal(sm.to_rgba(x[..., :3], bytes=bytes), expected)
13861386
# uint8 masked RGBA
13871387
xm = np.ma.masked_array(x, mask=np.zeros_like(x))
13881388
xm.mask[0, 0, 0] = True
13891389
expected = x.copy() if bytes else x.astype(np.float32)/255
13901390
expected[0, 0, 3] = 0
1391-
np.testing.assert_array_equal(sm.to_rgba(xm, bytes=bytes), expected)
1391+
np.testing.assert_almost_equal(sm.to_rgba(xm, bytes=bytes), expected)
13921392
# uint8 masked RGB
13931393
expected[..., 3] = alpha_1
13941394
expected[0, 0, 3] = 0
1395-
np.testing.assert_array_equal(sm.to_rgba(xm[..., :3], bytes=bytes), expected)
1395+
np.testing.assert_almost_equal(sm.to_rgba(xm[..., :3], bytes=bytes), expected)
13961396

13971397
# float RGBA
13981398
x = np.ones((2, 3, 4), dtype=float) * 0.5
13991399
expected = (x * 255).astype(np.uint8) if bytes else x.copy()
1400-
np.testing.assert_array_equal(sm.to_rgba(x, bytes=bytes), expected)
1400+
np.testing.assert_almost_equal(sm.to_rgba(x, bytes=bytes), expected)
14011401
# float RGB
14021402
expected[..., 3] = alpha_1
1403-
np.testing.assert_array_equal(sm.to_rgba(x[..., :3], bytes=bytes), expected)
1403+
np.testing.assert_almost_equal(sm.to_rgba(x[..., :3], bytes=bytes), expected)
14041404
# float masked RGBA
14051405
xm = np.ma.masked_array(x, mask=np.zeros_like(x))
14061406
xm.mask[0, 0, 0] = True
14071407
expected = (x * 255).astype(np.uint8) if bytes else x.copy()
14081408
expected[0, 0, 3] = 0
1409-
np.testing.assert_array_equal(sm.to_rgba(xm, bytes=bytes), expected)
1409+
np.testing.assert_almost_equal(sm.to_rgba(xm, bytes=bytes), expected)
14101410
# float masked RGB
14111411
expected[..., 3] = alpha_1
14121412
expected[0, 0, 3] = 0
1413-
np.testing.assert_array_equal(sm.to_rgba(xm[..., :3], bytes=bytes), expected)
1413+
np.testing.assert_almost_equal(sm.to_rgba(xm[..., :3], bytes=bytes), expected)
14141414

14151415

14161416
def test_failed_conversions():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.