Repository: Ouranosinc/xclim

Issue:
build failing against xarray master
ensembles creation tests seems to be failing with the travis build w/ xarray@master

We might want to take a minute to try to see why and try to get ahead of this... 

Discussion:
coveralls: ## Pull Request Test Coverage Report for [Build 1439](https://coveralls.io/builds/27962628)

* **3** of **3**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage remained the same at **90.967%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/27962628/badge)](https://coveralls.io/builds/27962628) |
| :-- | --: |
| Change from base [Build 1435](https://coveralls.io/builds/27961299): |  0.0% |
| Covered Lines: | 1722 |
| Relevant Lines: | 1893 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 66f7cba4..556b131c 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -5,6 +5,7 @@ History
 0.13.x (2020-01-10)
 -------------------
 * Reverted #311, removing the `_rolling` util function. Added optimal keywords to `rolling()` calls.
+* Fixed `ensembles.create_ensemble` errors for builds against xarray master branch.
 
 0.12.x-beta (2019-11-18)
 ------------------------
diff --git a/xclim/ensembles.py b/xclim/ensembles.py
index ab602bc4..8080f212 100644
--- a/xclim/ensembles.py
+++ b/xclim/ensembles.py
@@ -7,7 +7,6 @@ from typing import Union
 
 import numpy as np
 import pandas as pd
-import scipy
 import scipy.stats
 import xarray as xr
 from sklearn.cluster import KMeans
@@ -314,15 +313,16 @@ def _ens_align_datasets(
 
         if time_flag:
 
-            ds["time"] = xr.decode_cf(ds).time
-
-            ds["time"].values = pd.to_datetime(
+            cal1 = xr.decode_cf(ds).time
+            ds.drop_vars("time")
+            ds["time"] = pd.to_datetime(
                 {
-                    "year": ds.time.dt.year,
-                    "month": ds.time.dt.month,
-                    "day": ds.time.dt.day,
+                    "year": cal1.time.dt.year,
+                    "month": cal1.time.dt.month,
+                    "day": cal1.time.dt.day,
                 }
-            )
+            ).values
+
             # if dataset does not have the same time steps pad with nans
             if ds.time.min() > time_all.min() or ds.time.max() < time_all.max():
                 coords = {}


Test patch:
diff --git a/tests/test_ensembles.py b/tests/test_ensembles.py
index 55d11020..3bd9d27f 100644
--- a/tests/test_ensembles.py
+++ b/tests/test_ensembles.py
@@ -58,6 +58,7 @@ class TestEnsembleStats:
     def test_create_ensemble(self):
         ens = ensembles.create_ensemble(self.nc_files_simple)
         assert len(ens.realization) == len(self.nc_files_simple)
+        assert len(ens.time) == 151
 
         # create again using xr.Dataset objects
         ds_all = []
@@ -94,6 +95,7 @@ class TestEnsembleStats:
         assert len(ens.realization) == len(self.nc_files)
         assert ens.time.dt.year.min() == 1950
         assert ens.time.dt.year.max() == 2100
+        assert len(ens.time) == 151
 
         ii = [i for i, s in enumerate(self.nc_files) if "1970-2050" in s]
         # assert padded with nans