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

Method _dask_postpersist

xarray/core/dataset.py:721–770  ·  view source on GitHub ↗
(
        self, dsk: Mapping, *, rename: Mapping[str, str] | None = None
    )

Source from the content-addressed store, hash-verified

719 )
720
721 def _dask_postpersist(
722 self, dsk: Mapping, *, rename: Mapping[str, str] | None = None
723 ) -> Self:
724 from dask import is_dask_collection
725 from dask.highlevelgraph import HighLevelGraph
726 from dask.optimization import cull
727
728 variables = {}
729
730 for k, v in self._variables.items():
731 if not is_dask_collection(v):
732 variables[k] = v
733 continue
734
735 if isinstance(dsk, HighLevelGraph):
736 # dask >= 2021.3
737 # __dask_postpersist__() was called by dask.highlevelgraph.
738 # Don't use dsk.cull(), as we need to prevent partial layers:
739 # https://github.com/dask/dask/issues/7137
740 layers = v.__dask_layers__()
741 if rename:
742 layers = [rename.get(k, k) for k in layers]
743 dsk2 = dsk.cull_layers(layers)
744 elif rename: # pragma: nocover
745 # At the moment of writing, this is only for forward compatibility.
746 # replace_name_in_key requires dask >= 2021.3.
747 from dask.base import flatten, replace_name_in_key
748
749 keys = [
750 replace_name_in_key(k, rename) for k in flatten(v.__dask_keys__())
751 ]
752 dsk2, _ = cull(dsk, keys)
753 else:
754 # __dask_postpersist__() was called by dask.optimize or dask.persist
755 dsk2, _ = cull(dsk, v.__dask_keys__())
756
757 rebuild, args = v.__dask_postpersist__()
758 # rename was added in dask 2021.3
759 kwargs = {"rename": rename} if rename else {}
760 variables[k] = rebuild(dsk2, *args, **kwargs)
761
762 return type(self)._construct_direct(
763 variables,
764 self._coord_names,
765 self._dims,
766 self._attrs,
767 self._indexes,
768 self._encoding,
769 self._close,
770 )
771
772 def compute(self, **kwargs) -> Self:
773 """Trigger loading data into memory and return a new dataset.

Callers

nothing calls this directly

Calls 8

is_dask_collectionFunction · 0.85
typeFunction · 0.85
itemsMethod · 0.80
__dask_layers__Method · 0.45
getMethod · 0.45
__dask_keys__Method · 0.45
__dask_postpersist__Method · 0.45
_construct_directMethod · 0.45

Tested by

no test coverage detected