MCPcopy
hub / github.com/pydata/xarray / load_async

Method load_async

xarray/core/dataset.py:581–636  ·  view source on GitHub ↗

Trigger and await asynchronous loading of data into memory and return this dataset. Data will be computed and/or loaded from disk or a remote source. Unlike ``.compute``, the original dataset is modified and returned. Only works when opening data lazily from IO storage bac

(self, **kwargs)

Source from the content-addressed store, hash-verified

579 return self
580
581 async def load_async(self, **kwargs) -> Self:
582 """Trigger and await asynchronous loading of data into memory and return this dataset.
583
584 Data will be computed and/or loaded from disk or a remote source.
585
586 Unlike ``.compute``, the original dataset is modified and returned.
587
588 Only works when opening data lazily from IO storage backends which support lazy asynchronous loading.
589 Otherwise will raise a NotImplementedError.
590
591 Note users are expected to limit concurrency themselves - xarray does not internally limit concurrency in any way.
592
593 Parameters
594 ----------
595 **kwargs : dict
596 Additional keyword arguments passed on to ``dask.compute``.
597
598 Returns
599 -------
600 object : Dataset
601 Same object but with lazy data variables and coordinates as in-memory arrays.
602
603 See Also
604 --------
605 dask.compute
606 Dataset.compute
607 Dataset.load
608 DataArray.load_async
609 Variable.load_async
610 """
611 # TODO refactor this to pull out the common chunked_data codepath
612
613 # this blocks on chunked arrays but not on lazily indexed arrays
614
615 # access .data to coerce everything to numpy or dask arrays
616 chunked_data = {
617 k: v._data for k, v in self.variables.items() if is_chunked_array(v._data)
618 }
619 if chunked_data:
620 chunkmanager = get_chunked_array_type(*chunked_data.values())
621
622 # evaluate all the chunked arrays simultaneously
623 evaluated_data: tuple[np.ndarray[Any, Any], ...] = chunkmanager.compute(
624 *chunked_data.values(), **kwargs
625 )
626
627 for k, data in zip(chunked_data, evaluated_data, strict=False):
628 self.variables[k].data = data
629
630 # load everything else concurrently
631 coros = [
632 v.load_async() for k, v in self.variables.items() if k not in chunked_data
633 ]
634 await asyncio.gather(*coros)
635
636 return self
637
638 def __dask_tokenize__(self) -> object:

Calls 5

is_chunked_arrayFunction · 0.90
get_chunked_array_typeFunction · 0.90
itemsMethod · 0.80
valuesMethod · 0.45
computeMethod · 0.45