|
17 | 17 |
|
18 | 18 | from .core import duck_array_ops, indexing, ops, utils
|
19 | 19 | from .core.formatting import format_timestamp, first_n_items, last_item
|
20 |
| -from .core.variable import as_variable, Variable |
| 20 | +from .core.variable import as_variable, IndexVariable, Variable |
21 | 21 | from .core.pycompat import iteritems, OrderedDict, PY3, basestring
|
22 | 22 |
|
23 | 23 |
|
@@ -832,6 +832,15 @@ def _infer_dtype(array, name=None):
|
832 | 832 | def ensure_dtype_not_object(var, name=None):
|
833 | 833 | # TODO: move this from conventions to backends? (it's not CF related)
|
834 | 834 | if var.dtype.kind == 'O':
|
| 835 | + if (isinstance(var, IndexVariable) and |
| 836 | + isinstance(var.to_index(), pd.MultiIndex)): |
| 837 | + raise NotImplementedError( |
| 838 | + 'variable {!r} is a MultiIndex, which cannot yet be ' |
| 839 | + 'serialized to netCDF files ' |
| 840 | + '(https://github.com/pydata/xarray/issues/1077). Use ' |
| 841 | + 'reset_index() to convert MultiIndex levels into coordinate ' |
| 842 | + 'variables instead.'.format(name)) |
| 843 | + |
835 | 844 | dims, data, attrs, encoding = _var_as_tuple(var)
|
836 | 845 | missing = pd.isnull(data)
|
837 | 846 | if missing.any():
|
|
0 commit comments