Repository: jbusecke/xMIP (language: python)

Issue:
xarray 0.19.0 breaks cmip6_preprocessing
Our CI is currently [broken](https://github.com/jbusecke/cmip6_preprocessing/actions). I supect the new xarray release. 
Will investigate now.
Require xarray>=0.17.0
The support for `combine_attrs=drop_conflicts` needed for some of the postprocessing logic, was only added in v0.17.0. 

We need to make it explicit that older versions are not supported anymore. Otherwise #169 will happen to more users.


Discussion / hints:
should add an "upstream" test environment to avoid this kind of thing


Fix patch:
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 1b99e272..9b26bdc3 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -37,7 +37,7 @@ jobs:
       fail-fast: false
       matrix:
         os: ["ubuntu-latest"]
-        python-version: ["3.6", "3.7", "3.8", "3.9"]
+        python-version: ["3.7", "3.8", "3.9"]
     steps:
       - name: Cancel previous runs
         uses: styfle/cancel-workflow-action@0.9.0
diff --git a/ci/environment.yml b/ci/environment.yml
index a1220a16..592af31d 100644
--- a/ci/environment.yml
+++ b/ci/environment.yml
@@ -2,13 +2,14 @@ name: test_env_cmip6_preprocessing
 channels:
   - conda-forge
 dependencies:
-  - xarray
+  - xarray>=0.17.0
   - pandas<1.3 # remove this once https://github.com/pydata/xarray/issues/5581 is released
   - netcdf4
   - scipy
   - xgcm
   - cftime
   - regionmask
+  - cartopy
   - xesmf
   - xarrayutils
   - pytest-cov
diff --git a/docs/whats-new.rst b/docs/whats-new.rst
index 26dc9f2d..fff17471 100644
--- a/docs/whats-new.rst
+++ b/docs/whats-new.rst
@@ -6,9 +6,13 @@ What's New
 
 v0.6.0 (unreleased)
 -------------------
+Breaking Changes
+~~~~~~~~~~~~~~~~
+- Requires xarray>=0.17.0 and drops support for python 3.6 (:pull:`170`, :pull:`173`). By `Julius Busecke <https://github.com/jbusecke>`_
 
 Bugfixes
 ~~~~~~~~
+- Fixes incompatibility with upstream changes in xarray>=0.19.0 (:issue:`173`, :pull:`174`). By `Julius Busecke <https://github.com/jbusecke>`_
 
 - :py:func:`~cmip6_preprocessing.drift_removal.match_and_remove_drift` does now work with chunked (dask powered) datasets (:pull:`164`).By `Julius Busecke <https://github.com/jbusecke>`_
 
diff --git a/setup.cfg b/setup.cfg
index 16847b0b..33e020ca 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -41,9 +41,9 @@ classifiers =
     Operating System :: OS Independent
     Programming Language :: Python
     Programming Language :: Python :: 3
-    Programming Language :: Python :: 3.6
     Programming Language :: Python :: 3.7
     Programming Language :: Python :: 3.8
+    Programming Language :: Python :: 3.9
     # Dont change this one
     License :: OSI Approved :: MIT License
 
@@ -56,14 +56,14 @@ author_email = jbusecke@princeton.edu
 install_requires =
     numpy
     pandas
-    xarray
+    xarray>=0.17.0
     xgcm
     cftime
     xarrayutils
 setup_requires=
     setuptools
     setuptools-scm
-python_requires = >=3.6
+python_requires = >=3.7
 ################ Up until here
 
 include_package_data = True


Test patch:
diff --git a/ci/environment-cloud-test.yml b/ci/environment-cloud-test.yml
index 6b93fcba..4c821cbb 100644
--- a/ci/environment-cloud-test.yml
+++ b/ci/environment-cloud-test.yml
@@ -2,7 +2,7 @@ name: test_env_cmip6_preprocessing
 channels:
   - conda-forge
 dependencies:
-  - xarray
+  - xarray>=0.17.0
   - xgcm
   # Dependencies for the pangeo cloud data
   - intake-esm
diff --git a/tests/test_grids.py b/tests/test_grids.py
index 227b3b83..c9ee648e 100644
--- a/tests/test_grids.py
+++ b/tests/test_grids.py
@@ -23,24 +23,26 @@ def _add_small_rand(da):
 
 def _test_data(grid_label="gn", z_axis=True):
     xt = np.arange(4) + 1
-
     yt = np.arange(5) + 1
-
     zt = np.arange(6) + 1
+
     x = xr.DataArray(xt, coords=[("x", xt)])
     y = xr.DataArray(yt, coords=[("y", yt)])
     lev = xr.DataArray(zt, coords=[("lev", zt)])
 
     # Need to add a tracer here to get the tracer dimsuffix
-    coords = [("x", x), ("y", y)]
-    data = np.random.rand(len(x), len(y))
+    coords = [("x", x.data), ("y", y.data)]
+    data = np.random.rand(len(xt), len(yt))
+    dims = ["x", "y"]
 
     if z_axis:
-        coords.append(("lev", lev))
+        coords.append(("lev", lev.data))
         data = np.random.rand(len(x), len(y), len(lev))
+        dims = ["x", "y", "lev"]
 
     tr = xr.DataArray(
         data,
+        dims=dims,
         coords=coords,
     )