Repository: yt-project/yt

Issue:
BUG: incompatibility with most recent Cartopy versions
### Bug report

**Bug summary**

We have been pinning cartopy to version 0.18 for a couple month to mitigate upstream compatibility issues.
In order to enable testing yt on Windows + conda + Python 3.10, I tried to loosen that rule to allow more recent versions of cartopy (that are compatible with Python 3.10) to install.
Doing so I discovered that we have one failing test under cartopy 0.19 and 0.20
I am reporting it to keep track of the problem, but short term I consider just skipping it would be preferable to not testing Windows + Python 3.10


**Code for reproduction**

with cartopy 0.19 or newer installed:

```
pytest yt/visualization/tests/test_geo_projections.py::TestGeoProjections::test_nondefault_transform
```

**Actual outcome**

```
E           ValueError: Invalid vmin or vmax
```

This can be reproduced at least with Python 3.9 + cartopy 0.19 and Python 3.10 + cartopy 0.20, so I really think this is a cartopy issue, not a Python incompatibility.


Discussion:

Resolving patch:
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -140,19 +140,8 @@ def pytest_configure(config):
         )
 
     if find_spec("cartopy") is not None:
-        # cartopy still triggers this numpy warning
-        # last checked with cartopy 0.19.0
-        config.addinivalue_line(
-            "filterwarnings",
-            (
-                "ignore:`np.float` is a deprecated alias for the builtin `float`. "
-                "To silence this warning, use `float` by itself. "
-                "Doing this will not modify any behavior and is safe. "
-                "If you specifically wanted the numpy scalar type, use `np.float64` here."
-                ":DeprecationWarning: "
-            ),
-        )
-        # this warning *still* shows up on cartopy 0.19 so we'll ignore it
+        # This can be removed when cartopy 0.21 is released
+        # see https://github.com/SciTools/cartopy/pull/1957
         config.addinivalue_line(
             "filterwarnings",
             (
diff --git a/yt/visualization/base_plot_types.py b/yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -269,7 +269,16 @@ def _init_image(self, data, cbnorm, cblinthresh, cmap, extent, aspect):
             # instances.  It is left as a historical note because we will
             # eventually need some form of it.
             # self.axes.set_extent(extent)
-            pass
+
+            # possibly related issue (operation order dependency)
+            # https://github.com/SciTools/cartopy/issues/1468
+
+            # in cartopy 0.19 (or 0.20), some intented behaviour changes produced an
+            # incompatibility here where default values for extent would lead to a crash.
+            # A solution is to let the transform object set the image extents internally
+            # see https://github.com/SciTools/cartopy/issues/1955
+            extent = None
+
         self.image = self.axes.imshow(
             data.to_ndarray(),
             origin="lower",


Test patch:
diff --git a/tests/cartopy_requirements.txt b/tests/cartopy_requirements.txt
deleted file mode 100644
--- a/tests/cartopy_requirements.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-# cartopy and its dependencies are non trivial to install
-# so we can't easily put these specs into setup.cfg
-shapely
---no-binary=shapely
-cartopy~=0.18.0
diff --git a/tests/ci_install.sh b/tests/ci_install.sh
--- a/tests/ci_install.sh
+++ b/tests/ci_install.sh
@@ -16,13 +16,7 @@ osx|macOS)
     sudo mkdir -p /usr/local/man
     sudo chown -R "${USER}:admin" /usr/local/man
     brew update
-    # proj can be unpinned when upstream incompatibility issue is resolved. See
-    # https://github.com/SciTools/cartopy/issues/1140
-    export LDFLAGS="$LDFLAGS -L/usr/local/opt/proj@7/lib"
-    export CPPFLAGS="$CPPFLAGS -I/usr/local/opt/proj@7/include"
-    export CFLAGS="$CFLAGS -I/usr/local/opt/proj@7/include"
-    export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/proj@7/lib/pkgconfig"
-    HOMEBREW_NO_AUTO_UPDATE=1 brew install hdf5 proj@7 geos open-mpi netcdf ccache
+    HOMEBREW_NO_AUTO_UPDATE=1 brew install hdf5 proj geos open-mpi netcdf ccache
     ;;
 esac
 
diff --git a/tests/windows_conda_requirements.txt b/tests/windows_conda_requirements.txt
--- a/tests/windows_conda_requirements.txt
+++ b/tests/windows_conda_requirements.txt
@@ -1,6 +1,6 @@
 numpy>=1.19.4
 cython>=0.29.21,<3.0
-cartopy~=0.18.0
+cartopy>=0.20.1
 h5py~=3.1.0
 matplotlib!=3.4.2,>=2.2.3,<3.6  # keep in sync with setup.cfg
 scipy~=1.5.0