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

Method test_copy

xarray/tests/test_dataset.py:3263–3290  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3261 assert_identical(expected, actual)
3262
3263 def test_copy(self) -> None:
3264 data = create_test_data()
3265 data.attrs["Test"] = [1, 2, 3]
3266
3267 for copied in [data.copy(deep=False), copy(data)]:
3268 assert_identical(data, copied)
3269 assert data.encoding == copied.encoding
3270 # Note: IndexVariable objects with string dtype are always
3271 # copied because of xarray.core.indexes.safe_cast_to_index.
3272 # Limiting the test to data variables.
3273 for k in data.data_vars:
3274 v0 = data.variables[k]
3275 v1 = copied.variables[k]
3276 assert source_ndarray(v0.data) is source_ndarray(v1.data)
3277 copied["foo"] = ("z", np.arange(5))
3278 assert "foo" not in data
3279
3280 copied.attrs["foo"] = "bar"
3281 assert "foo" not in data.attrs
3282 assert data.attrs["Test"] is copied.attrs["Test"]
3283
3284 for copied in [data.copy(deep=True), deepcopy(data)]:
3285 assert_identical(data, copied)
3286 for k, v0 in data.variables.items():
3287 v1 = copied.variables[k]
3288 assert v0 is not v1
3289
3290 assert data.attrs["Test"] is not copied.attrs["Test"]
3291
3292 def test_copy_with_data(self) -> None:
3293 orig = create_test_data()

Callers

nothing calls this directly

Calls 6

create_test_dataFunction · 0.90
assert_identicalFunction · 0.90
source_ndarrayFunction · 0.90
arangeMethod · 0.80
itemsMethod · 0.80
copyMethod · 0.45

Tested by

no test coverage detected