Skip to content

Commit

Permalink
FIX: if regrid shape is passed, we need to remove it from the super call
Browse files Browse the repository at this point in the history
The regrid doesn't do anything, so we should warn the user that we are
getting rid of it and continuing on.
  • Loading branch information
greglucas committed Jul 11, 2024
1 parent ca2832e commit b46c4d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,11 @@ def imshow(self, img, *args, **kwargs):

if (transform is None or transform == self.transData or
same_projection and inside_bounds):
if "regrid_shape" in kwargs:
warnings.warn("ignoring regrid_shape because it doesn't do anything "
"when working in the same projection. To avoid this "
"warning, remove the 'regrid_shape' keyword argument.")
kwargs.pop("regrid_shape")
result = super().imshow(img, *args, **kwargs)
else:
extent = kwargs.pop('extent', None)
Expand Down
10 changes: 10 additions & 0 deletions lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ def test_imshow_wrapping():
assert ax.get_xlim() == (-180, 180)


def test_imshow_arguments():
"""Smoke test for imshow argument passing in the fast-path"""
ax = plt.axes(projection=ccrs.PlateCarree())
# Set the regrid_shape parameter to ensure it isn't passed to Axes.imshow()
# in the fast-path call to super()
with pytest.warns(UserWarning, match="ignoring regrid_shape"):
ax.imshow(np.random.random((10, 10)), transform=ccrs.PlateCarree(),
extent=(-180, 180, -90, 90), regrid_shape=500)


def test_imshow_rgba():
# tests that the alpha of a RGBA array passed to imshow is set to 0
# instead of masked
Expand Down

0 comments on commit b46c4d5

Please sign in to comment.