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

Method _copy

xarray/core/dataset.py:1133–1174  ·  view source on GitHub ↗
(
        self,
        deep: bool = False,
        data: DataVars | None = None,
        memo: dict[int, Any] | None = None,
    )

Source from the content-addressed store, hash-verified

1131 return self._copy(deep=deep, data=data)
1132
1133 def _copy(
1134 self,
1135 deep: bool = False,
1136 data: DataVars | None = None,
1137 memo: dict[int, Any] | None = None,
1138 ) -> Self:
1139 if data is None:
1140 data = {}
1141 elif not utils.is_dict_like(data):
1142 raise ValueError("Data must be dict-like")
1143
1144 if data:
1145 var_keys = set(self.data_vars.keys())
1146 data_keys = set(data.keys())
1147 keys_not_in_vars = data_keys - var_keys
1148 if keys_not_in_vars:
1149 raise ValueError(
1150 "Data must only contain variables in original "
1151 f"dataset. Extra variables: {keys_not_in_vars}"
1152 )
1153 keys_missing_from_data = var_keys - data_keys
1154 if keys_missing_from_data:
1155 raise ValueError(
1156 "Data must contain all variables in original "
1157 f"dataset. Data is missing {keys_missing_from_data}"
1158 )
1159
1160 indexes, index_vars = self.xindexes.copy_indexes(deep=deep)
1161
1162 variables = {}
1163 for k, v in self._variables.items():
1164 if k in index_vars:
1165 variables[k] = index_vars[k]
1166 else:
1167 variables[k] = v._copy(deep=deep, data=data.get(k), memo=memo)
1168
1169 attrs = copy.deepcopy(self._attrs, memo) if deep else copy.copy(self._attrs)
1170 encoding = (
1171 copy.deepcopy(self._encoding, memo) if deep else copy.copy(self._encoding)
1172 )
1173
1174 return self._replace(variables, indexes=indexes, attrs=attrs, encoding=encoding)
1175
1176 def __copy__(self) -> Self:
1177 return self._copy(deep=False)

Callers 3

copyMethod · 0.95
__copy__Method · 0.95
__deepcopy__Method · 0.95

Calls 6

_replaceMethod · 0.95
keysMethod · 0.80
copy_indexesMethod · 0.80
itemsMethod · 0.80
getMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected