Skip to content

Commit 59929db

Browse files
gfyoungstangirala
authored andcommitted
MAINT: Give nice error message if xarray import fails (#16664)
1 parent 1ef3a63 commit 59929db

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pandas/core/generic.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,17 @@ def to_xarray(self):
15011501
-----
15021502
See the `xarray docs <http://xarray.pydata.org/en/stable/>`__
15031503
"""
1504-
import xarray
1504+
1505+
try:
1506+
import xarray
1507+
except ImportError:
1508+
# Give a nice error message
1509+
raise ImportError("the xarray library is not installed\n"
1510+
"you can install via conda\n"
1511+
"conda install xarray\n"
1512+
"or via pip\n"
1513+
"pip install xarray\n")
1514+
15051515
if self.ndim == 1:
15061516
return xarray.DataArray.from_series(self)
15071517
elif self.ndim == 2:

0 commit comments

Comments
 (0)