From 96785fa3227e430cf53bd28c6e86617105320208 Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Fri, 13 Dec 2019 10:39:43 -0500 Subject: [PATCH 1/2] Provide shape info in shape mismatch error. --- xarray/core/variable.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index ac4b367f66d..78f90df79e9 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -346,7 +346,10 @@ def data(self): def data(self, data): data = as_compatible_data(data) if data.shape != self.shape: - raise ValueError("replacement data must match the Variable's shape") + raise ValueError( + f"replacement data must match the Variable's shape. " + f"data.shape is {data.shape}; Variable.shape is {self.shape}" + ) self._data = data def load(self, **kwargs): From 63662574691919d874ea572bdee346f9e19c2e0f Mon Sep 17 00:00:00 2001 From: Dan Allan Date: Fri, 13 Dec 2019 10:48:55 -0500 Subject: [PATCH 2/2] Reword error message. Co-Authored-By: Deepak Cherian --- xarray/core/variable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 78f90df79e9..17ecdf62730 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -348,7 +348,7 @@ def data(self, data): if data.shape != self.shape: raise ValueError( f"replacement data must match the Variable's shape. " - f"data.shape is {data.shape}; Variable.shape is {self.shape}" + f"replacement data has shape {data.shape}; Variable has shape {self.shape}" ) self._data = data