Skip to content

Commit

Permalink
Merge pull request #25813 from ksunden/npy_prec_robustness
Browse files Browse the repository at this point in the history
[TST] Adjust tests to be more tolerant to floating point math operations being imprecise
  • Loading branch information
oscargus committed May 6, 2023
2 parents f1a8b92 + a59269d commit 4bdae2e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4415,7 +4415,8 @@ def test_mollweide_forward_inverse_closure():

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

Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,13 @@ def test_axvline_axvspan_do_not_modify_rlims():
def test_cursor_precision():
ax = plt.subplot(projection="polar")
# Higher radii correspond to higher theta-precisions.
assert ax.format_coord(0, 0) == "θ=0π (0°), r=0.000"
assert ax.format_coord(0, 0.005) == "θ=0.0π (0°), r=0.005"
assert ax.format_coord(0, .1) == "θ=0.00π (0°), r=0.100"
assert ax.format_coord(0, 1) == "θ=0.000π (0.0°), r=1.000"
assert ax.format_coord(1, 0) == "θ=0.3π (57°), r=0.000"
assert ax.format_coord(1, 0.005) == "θ=0.3π (57°), r=0.005"
assert ax.format_coord(1, .1) == "θ=0.32π (57°), r=0.100"
assert ax.format_coord(1, 1) == "θ=0.318π (57.3°), r=1.000"
assert ax.format_coord(2, 0) == "θ=0.6π (115°), r=0.000"
assert ax.format_coord(2, 0.005) == "θ=0.6π (115°), r=0.005"
assert ax.format_coord(2, .1) == "θ=0.64π (115°), r=0.100"
assert ax.format_coord(2, 1) == "θ=0.637π (114.6°), r=1.000"

Expand Down
6 changes: 3 additions & 3 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ def test_bar3d_lightsource():

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


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

0 comments on commit 4bdae2e

Please sign in to comment.