|
15 | 15 | from ..core.utils import close_on_error, is_remote_uri |
16 | 16 | from ..core.pycompat import basestring |
17 | 17 |
|
| 18 | +DATAARRAY_NAME = '__xarray_dataarray_name__' |
| 19 | +DATAARRAY_VARIABLE = '__xarray_dataarray_variable__' |
18 | 20 |
|
19 | 21 | def _get_default_engine(path, allow_remote=False): |
20 | 22 | if allow_remote and is_remote_uri(path): # pragma: no cover |
@@ -348,21 +350,21 @@ def open_dataarray(filename_or_obj, group=None, decode_cf=True, |
348 | 350 | chunks, lock, drop_variables) |
349 | 351 |
|
350 | 352 | if len(dataset.data_vars) != 1: |
351 | | - raise ValueError('Given file dataset contains more than one variable. ' |
352 | | - 'Please read with xarray.open_dataset and then select ' |
353 | | - 'the variable you want.') |
| 353 | + raise ValueError('Given file dataset contains more than one data ' |
| 354 | + 'variable. Please read with xarray.open_dataset and ' |
| 355 | + 'then select the variable you want.') |
354 | 356 | else: |
355 | 357 | data_array, = dataset.data_vars.values() |
356 | 358 |
|
357 | 359 | data_array._file_obj = dataset._file_obj |
358 | 360 |
|
359 | 361 | # Reset names if they were changed during saving |
360 | 362 | # to ensure that we can 'roundtrip' perfectly |
361 | | - if '__xarray_dataarray_name__' in dataset.attrs: |
362 | | - data_array.name = dataset.attrs['__xarray_dataarray_name__'] |
363 | | - del dataset.attrs['__xarray_dataarray_name__'] |
| 363 | + if DATAARRAY_NAME in dataset.attrs: |
| 364 | + data_array.name = dataset.attrs[DATAARRAY_NAME] |
| 365 | + del dataset.attrs[DATAARRAY_NAME] |
364 | 366 |
|
365 | | - if data_array.name == '__xarray_dataarray_variable__': |
| 367 | + if data_array.name == DATAARRAY_VARIABLE: |
366 | 368 | data_array.name = None |
367 | 369 |
|
368 | 370 | return data_array |
|
0 commit comments