|
12 | 12 | from ..core.utils import close_on_error, is_remote_uri |
13 | 13 | from ..core.pycompat import basestring |
14 | 14 |
|
| 15 | +DATAARRAY_NAME = '__xarray_dataarray_name__' |
| 16 | +DATAARRAY_VARIABLE = '__xarray_dataarray_variable__' |
15 | 17 |
|
16 | 18 | def _get_default_engine(path, allow_remote=False): |
17 | 19 | if allow_remote and is_remote_uri(path): # pragma: no cover |
@@ -314,21 +316,21 @@ def open_dataarray(filename_or_obj, group=None, decode_cf=True, |
314 | 316 | chunks, lock, drop_variables) |
315 | 317 |
|
316 | 318 | if len(dataset.data_vars) != 1: |
317 | | - raise ValueError('Given file dataset contains more than one variable. ' |
318 | | - 'Please read with xarray.open_dataset and then select ' |
319 | | - 'the variable you want.') |
| 319 | + raise ValueError('Given file dataset contains more than one data ' |
| 320 | + 'variable. Please read with xarray.open_dataset and ' |
| 321 | + 'then select the variable you want.') |
320 | 322 | else: |
321 | 323 | data_array, = dataset.data_vars.values() |
322 | 324 |
|
323 | 325 | data_array._file_obj = dataset._file_obj |
324 | 326 |
|
325 | 327 | # Reset names if they were changed during saving |
326 | 328 | # to ensure that we can 'roundtrip' perfectly |
327 | | - if '__xarray_dataarray_name__' in dataset.attrs: |
328 | | - data_array.name = dataset.attrs['__xarray_dataarray_name__'] |
329 | | - del dataset.attrs['__xarray_dataarray_name__'] |
| 329 | + if DATAARRAY_NAME in dataset.attrs: |
| 330 | + data_array.name = dataset.attrs[DATAARRAY_NAME] |
| 331 | + del dataset.attrs[DATAARRAY_NAME] |
330 | 332 |
|
331 | | - if data_array.name == '__xarray_dataarray_variable__': |
| 333 | + if data_array.name == DATAARRAY_VARIABLE: |
332 | 334 | data_array.name = None |
333 | 335 |
|
334 | 336 | return data_array |
|
0 commit comments