Skip to content

Commit 4bdae2e

Browse files
authored
Merge pull request matplotlib#25813 from ksunden/npy_prec_robustness
[TST] Adjust tests to be more tolerant to floating point math operations being imprecise
2 parents f1a8b92 + a59269d commit 4bdae2e

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lib/matplotlib/tests/test_axes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4415,7 +4415,8 @@ def test_mollweide_forward_inverse_closure():
44154415

44164416
# set up 1-degree grid in longitude, latitude
44174417
lon = np.linspace(-np.pi, np.pi, 360)
4418-
lat = np.linspace(-np.pi / 2.0, np.pi / 2.0, 180)
4418+
# The poles are degenerate and thus sensitive to floating point precision errors
4419+
lat = np.linspace(-np.pi / 2.0, np.pi / 2.0, 180)[1:-1]
44194420
lon, lat = np.meshgrid(lon, lat)
44204421
ll = np.vstack((lon.flatten(), lat.flatten())).T
44214422

lib/matplotlib/tests/test_polar.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,13 @@ def test_axvline_axvspan_do_not_modify_rlims():
425425
def test_cursor_precision():
426426
ax = plt.subplot(projection="polar")
427427
# Higher radii correspond to higher theta-precisions.
428-
assert ax.format_coord(0, 0) == "θ=0π (0°), r=0.000"
428+
assert ax.format_coord(0, 0.005) == "θ=0.0π (0°), r=0.005"
429429
assert ax.format_coord(0, .1) == "θ=0.00π (0°), r=0.100"
430430
assert ax.format_coord(0, 1) == "θ=0.000π (0.0°), r=1.000"
431-
assert ax.format_coord(1, 0) == "θ=0.3π (57°), r=0.000"
431+
assert ax.format_coord(1, 0.005) == "θ=0.3π (57°), r=0.005"
432432
assert ax.format_coord(1, .1) == "θ=0.32π (57°), r=0.100"
433433
assert ax.format_coord(1, 1) == "θ=0.318π (57.3°), r=1.000"
434-
assert ax.format_coord(2, 0) == "θ=0.6π (115°), r=0.000"
434+
assert ax.format_coord(2, 0.005) == "θ=0.6π (115°), r=0.005"
435435
assert ax.format_coord(2, .1) == "θ=0.64π (115°), r=0.100"
436436
assert ax.format_coord(2, 1) == "θ=0.637π (114.6°), r=1.000"
437437

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ def test_bar3d_lightsource():
200200

201201
# Testing that the custom 90° lightsource produces different shading on
202202
# the top facecolors compared to the default, and that those colors are
203-
# precisely the colors from the colormap, due to the illumination parallel
204-
# to the z-axis.
205-
np.testing.assert_array_equal(color, collection._facecolor3d[1::6])
203+
# precisely (within floating point rounding errors of 4 ULP) the colors
204+
# from the colormap, due to the illumination parallel to the z-axis.
205+
np.testing.assert_array_max_ulp(color, collection._facecolor3d[1::6], 4)
206206

207207

208208
@mpl3d_image_comparison(['contour3d.png'], style='mpl20')

0 commit comments

Comments
 (0)