From ca1726601393cb6d3555b59af8a59b674cb54da4 Mon Sep 17 00:00:00 2001 From: TomNicholas Date: Tue, 6 Feb 2024 00:41:34 -0500 Subject: [PATCH] only wrap BackendArrays in CopyOnWriteArray --- xarray/backends/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 670a0ec6d68..8216753eb11 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -236,7 +236,10 @@ def _protect_dataset_variables_inplace(dataset, cache): for name, variable in dataset.variables.items(): if name not in dataset._indexes: # no need to protect IndexVariable objects - data = indexing.CopyOnWriteArray(variable._data) + if isinstance(variable._data, backends.BackendArray): + data = indexing.CopyOnWriteArray(variable._data) + else: + data = variable.data if cache: data = indexing.MemoryCachedArray(data) variable.data = data