Skip to content

Commit af08528

Browse files
authored
adapt more tests to the copy-on-write behavior of pandas (#8940)
* mirror the `Dataset` `copy_coords` test * avoid modifying the values of a `pandas` series
1 parent aa08785 commit af08528

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

xarray/tests/test_dataarray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3945,7 +3945,8 @@ def test_copy_coords(self, deep, expected_orig) -> None:
39453945
dims=["a", "b", "c"],
39463946
)
39473947
da_cp = da.copy(deep)
3948-
da_cp["a"].data[0] = 999
3948+
new_a = np.array([999, 2])
3949+
da_cp.coords["a"] = da_cp["a"].copy(data=new_a)
39493950

39503951
expected_cp = xr.DataArray(
39513952
xr.IndexVariable("a", np.array([999, 2])),

xarray/tests/test_missing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ def test_interpolate_pd_compat_non_uniform_index():
164164
# for the linear methods. This next line inforces the xarray
165165
# fill_value convention on the pandas output. Therefore, this test
166166
# only checks that interpolated values are the same (not nans)
167-
expected.values[pd.isnull(actual.values)] = np.nan
167+
expected_values = expected.values.copy()
168+
expected_values[pd.isnull(actual.values)] = np.nan
168169

169-
np.testing.assert_allclose(actual.values, expected.values)
170+
np.testing.assert_allclose(actual.values, expected_values)
170171

171172

172173
@requires_scipy

0 commit comments

Comments
 (0)