From 8925f00be8d245c8c99975ccfe91f8ed06b4d6a4 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Sun, 11 Jun 2017 02:13:08 -0700 Subject: [PATCH] MAINT: Give nice error message if xarray import fails --- pandas/core/generic.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index accb7d0db1d2c..a674c3ca28ae8 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1501,7 +1501,17 @@ def to_xarray(self): ----- See the `xarray docs `__ """ - import xarray + + try: + import xarray + except ImportError: + # Give a nice error message + raise ImportError("the xarray library is not installed\n" + "you can install via conda\n" + "conda install xarray\n" + "or via pip\n" + "pip install xarray\n") + if self.ndim == 1: return xarray.DataArray.from_series(self) elif self.ndim == 2: