Skip to content

Commit

Permalink
adapt more tests to the copy-on-write behavior of pandas (#8940)
Browse files Browse the repository at this point in the history
* mirror the `Dataset` `copy_coords` test

* avoid modifying the values of a `pandas` series
  • Loading branch information
keewis authored Apr 13, 2024
1 parent aa08785 commit af08528
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3945,7 +3945,8 @@ def test_copy_coords(self, deep, expected_orig) -> None:
dims=["a", "b", "c"],
)
da_cp = da.copy(deep)
da_cp["a"].data[0] = 999
new_a = np.array([999, 2])
da_cp.coords["a"] = da_cp["a"].copy(data=new_a)

expected_cp = xr.DataArray(
xr.IndexVariable("a", np.array([999, 2])),
Expand Down
5 changes: 3 additions & 2 deletions xarray/tests/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ def test_interpolate_pd_compat_non_uniform_index():
# for the linear methods. This next line inforces the xarray
# fill_value convention on the pandas output. Therefore, this test
# only checks that interpolated values are the same (not nans)
expected.values[pd.isnull(actual.values)] = np.nan
expected_values = expected.values.copy()
expected_values[pd.isnull(actual.values)] = np.nan

np.testing.assert_allclose(actual.values, expected.values)
np.testing.assert_allclose(actual.values, expected_values)


@requires_scipy
Expand Down

0 comments on commit af08528

Please sign in to comment.