Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xarray/coding/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def safe_setitem(dest, key: Hashable, value, name: T_Name = None):
if key in dest:
var_str = f" on variable {name!r}" if name else ""
raise ValueError(
f"failed to prevent overwriting existing key {key} in attrs{var_str}. "
f"Key '{key}' already exists in attrs{var_str}, and will not be overwritten. "
"This is probably an encoding field used by xarray to describe "
"how a variable is serialized. To proceed, remove this key from "
"the variable's attributes manually."
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_coding_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ def test_timedelta_decode_via_dtype_invalid_encoding() -> None:
attrs = {"dtype": "timedelta64[s]", "units": "seconds"}
encoding = {"units": "foo"}
encoded = Variable(["time"], [0, 1, 2], attrs=attrs, encoding=encoding)
with pytest.raises(ValueError, match="failed to prevent"):
with pytest.raises(ValueError, match=r"Key .* already exists"):
conventions.decode_cf_variable("timedeltas", encoded)


Expand All @@ -2097,7 +2097,7 @@ def test_timedelta_encode_via_dtype_invalid_attribute(attribute) -> None:
timedeltas = pd.timedelta_range(0, freq="D", periods=3)
attrs = {attribute: "foo"}
variable = Variable(["time"], timedeltas, attrs=attrs)
with pytest.raises(ValueError, match="failed to prevent"):
with pytest.raises(ValueError, match=r"Key .* already exists"):
conventions.encode_cf_variable(variable)


Expand Down
Loading