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

Method copy

xarray/core/variable.py:2886–2928  ·  view source on GitHub ↗

Returns a copy of this object. `deep` is ignored since data is stored in the form of pandas.Index, which is already immutable. Dimensions, attributes and encodings are always copied. Use `data` to create a new object with the same structure as original but e

(
        self, deep: bool = True, data: T_DuckArray | np.typing.ArrayLike | None = None
    )

Source from the content-addressed store, hash-verified

2884 return cls(first_var.dims, data, attrs)
2885
2886 def copy(
2887 self, deep: bool = True, data: T_DuckArray | np.typing.ArrayLike | None = None
2888 ):
2889 """Returns a copy of this object.
2890
2891 `deep` is ignored since data is stored in the form of
2892 pandas.Index, which is already immutable. Dimensions, attributes
2893 and encodings are always copied.
2894
2895 Use `data` to create a new object with the same structure as
2896 original but entirely new data.
2897
2898 Parameters
2899 ----------
2900 deep : bool, default: True
2901 Deep is ignored when data is given. Whether the data array is
2902 loaded into memory and copied onto the new object. Default is True.
2903 data : array_like, optional
2904 Data to use in the new object. Must have same shape as original.
2905
2906 Returns
2907 -------
2908 object : Variable
2909 New object with dimensions, attributes, encodings, and optionally
2910 data copied from original.
2911 """
2912 if data is None:
2913 ndata = self._data
2914
2915 if deep:
2916 ndata = copy.deepcopy(ndata, None)
2917
2918 else:
2919 ndata = as_compatible_data(data)
2920 if self.shape != ndata.shape:
2921 raise ValueError(
2922 f"Data shape {ndata.shape} must match shape of object {self.shape}"
2923 )
2924
2925 attrs = copy.deepcopy(self._attrs) if deep else copy.copy(self._attrs)
2926 encoding = copy.deepcopy(self._encoding) if deep else copy.copy(self._encoding)
2927
2928 return self._replace(data=ndata, attrs=attrs, encoding=encoding)
2929
2930 def equals(self, other, equiv=None):
2931 # if equiv is specified, super up

Callers 14

chunkMethod · 0.95
_as_sparseMethod · 0.95
_to_denseMethod · 0.95
to_index_variableMethod · 0.95
as_variableFunction · 0.45
_newMethod · 0.45
_copyMethod · 0.45
_replaceMethod · 0.45
computeMethod · 0.45

Calls 2

as_compatible_dataFunction · 0.85
_replaceMethod · 0.45

Tested by 2