From afbb531b856658bcf63ebcb405e340b5f8c68498 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Thu, 13 Jul 2023 11:33:25 +0100 Subject: [PATCH] TST: add test for GeoQuadMesh.set_array without wrap --- lib/cartopy/tests/mpl/test_mpl_integration.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/cartopy/tests/mpl/test_mpl_integration.py b/lib/cartopy/tests/mpl/test_mpl_integration.py index 222ca3fef..32212b3b0 100644 --- a/lib/cartopy/tests/mpl/test_mpl_integration.py +++ b/lib/cartopy/tests/mpl/test_mpl_integration.py @@ -506,6 +506,37 @@ def test_pcolormesh_set_array_with_mask(mesh_data_kind): return fig +def test_pcolormesh_set_array_nowrap(): + # Roundtrip check that set_array works with the correct shaped arrays + nx, ny = 36, 18 + xbnds = np.linspace(-60, 60, nx, endpoint=True) + ybnds = np.linspace(-80, 80, ny, endpoint=True) + xbnds, ybnds = np.meshgrid(xbnds, ybnds) + + rng = np.random.default_rng() + print(f"{xbnds.shape=}, {ybnds.shape=}") + data = rng.random((17, 35)) + + ax = plt.figure().add_subplot(projection=ccrs.PlateCarree()) + mesh = ax.pcolormesh(xbnds, ybnds, data) + assert not hasattr(mesh, '_wrapped_collection_fix') + + expected = data + if MPL_VERSION.release[:2] < (3, 8): + expected = expected.ravel() + np.testing.assert_array_equal(mesh.get_array(), expected) + + # For backwards compatibility, check we can set a flattened array + data = rng.random(35 * 17) + mesh.set_array(data) + np.testing.assert_array_equal(mesh.get_array(), data.reshape(17, 35)) + + # Check that we can set a 2D array even if previous was flat + data = rng.random((17, 35)) + mesh.set_array(data) + np.testing.assert_array_equal(mesh.get_array(), data) + + @pytest.mark.natural_earth @pytest.mark.mpl_image_compare(filename='pcolormesh_global_wrap3.png', tolerance=1.42)