(self)
| 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() |
nothing calls this directly
no test coverage detected