MCPcopy Index your code
hub / github.com/pydata/xarray / _copy

Method _copy

xarray/core/variable.py:942–974  ·  view source on GitHub ↗
(
        self,
        deep: bool = True,
        data: T_DuckArray | np.typing.ArrayLike | None = None,
        memo: dict[int, Any] | None = None,
    )

Source from the content-addressed store, hash-verified

940 return self._replace(encoding={})
941
942 def _copy(
943 self,
944 deep: bool = True,
945 data: T_DuckArray | np.typing.ArrayLike | None = None,
946 memo: dict[int, Any] | None = None,
947 ) -> Self:
948 if data is None:
949 data_old = self._data
950
951 if not isinstance(data_old, indexing.MemoryCachedArray):
952 ndata = data_old
953 else:
954 # don't share caching between copies
955 # TODO: MemoryCachedArray doesn't match the array api:
956 ndata = indexing.MemoryCachedArray(data_old.array) # type: ignore[assignment]
957
958 if deep:
959 ndata = copy.deepcopy(ndata, memo)
960
961 else:
962 ndata = as_compatible_data(data)
963 if self.shape != ndata.shape:
964 raise ValueError(
965 f"Data shape {ndata.shape} must match shape of object {self.shape}"
966 )
967
968 attrs = copy.deepcopy(self._attrs, memo) if deep else copy.copy(self._attrs)
969 encoding = (
970 copy.deepcopy(self._encoding, memo) if deep else copy.copy(self._encoding)
971 )
972
973 # note: dims is already an immutable tuple
974 return self._replace(data=ndata, attrs=attrs, encoding=encoding)
975
976 def _replace(
977 self,

Callers

nothing calls this directly

Calls 3

_replaceMethod · 0.95
as_compatible_dataFunction · 0.85
copyMethod · 0.45

Tested by

no test coverage detected