{"instance_id": "pydata__xarray-4695", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py\nindex 32b24ef1..6316afd5 100644\n--- a/xarray/core/dataarray.py\n+++ b/xarray/core/dataarray.py\n@@ -196,7 +196,7 @@ class _LocIndexer:\n             # expand the indexer so we can handle Ellipsis\n             labels = indexing.expanded_indexer(key, self.data_array.ndim)\n             key = dict(zip(self.data_array.dims, labels))\n-        return self.data_array.sel(**key)\n+        return self.data_array.sel(key)\n \n     def __setitem__(self, key, value) -> None:\n         if not utils.is_dict_like(key):\n", "model": "claude-haiku-5-5", "steps": 10, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 13, "steps": 10}], "ms": 11772}
{"instance_id": "pydata__xarray-4966", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/coding/variables.py b/xarray/coding/variables.py\nindex b035ff82..938752c4 100644\n--- a/xarray/coding/variables.py\n+++ b/xarray/coding/variables.py\n@@ -316,6 +316,14 @@ class UnsignedIntegerCoder(VariableCoder):\n                     if \"_FillValue\" in attrs:\n                         new_fill = unsigned_dtype.type(attrs[\"_FillValue\"])\n                         attrs[\"_FillValue\"] = new_fill\n+            elif data.dtype.kind == \"u\":\n+                if unsigned == \"false\":\n+                    signed_dtype = np.dtype(\"i%s\" % data.dtype.itemsize)\n+                    transform = partial(np.asarray, dtype=signed_dtype)\n+                    data = lazy_elemwise_func(data, transform, signed_dtype)\n+                    if \"_FillValue\" in attrs:\n+                        new_fill = signed_dtype.type(attrs[\"_FillValue\"])\n+                        attrs[\"_FillValue\"] = new_fill\n             else:\n                 warnings.warn(\n                     \"variable %r has _Unsigned attribute but is not \"\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 19, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 19, "steps": 7}], "ms": 17049}
{"instance_id": "pydata__xarray-6461", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/computation.py b/xarray/core/computation.py\nindex 7676d8e5..f31918ce 100644\n--- a/xarray/core/computation.py\n+++ b/xarray/core/computation.py\n@@ -1829,7 +1829,7 @@ def where(cond, x, y, keep_attrs=None):\n     if keep_attrs is True:\n         # keep the attributes of x, the second parameter, by default to\n         # be consistent with the `where` method of `DataArray` and `Dataset`\n-        keep_attrs = lambda attrs, context: attrs[1]\n+        keep_attrs = lambda attrs, context: getattr(x, \"attrs\", {})\n \n     # alignment for three arguments is complicated, so don't support it yet\n     return apply_ufunc(\n", "model": "claude-haiku-5-5", "steps": 11, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 13, "steps": 11}], "ms": 20740}
{"instance_id": "pydata__xarray-6599", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/computation.py b/xarray/core/computation.py\nindex 823cbe02..76ed0ad7 100644\n--- a/xarray/core/computation.py\n+++ b/xarray/core/computation.py\n@@ -1934,10 +1934,16 @@ def _ensure_numeric(data: T_Xarray) -> T_Xarray:\n \n     def to_floatable(x: DataArray) -> DataArray:\n         if x.dtype.kind in \"mM\":\n+            # datetimes are offset from the epoch; timedeltas are offset from zero\n+            offset = (\n+                np.datetime64(\"1970-01-01\")\n+                if x.dtype.kind == \"M\"\n+                else np.timedelta64(0, \"ns\")\n+            )\n             return x.copy(\n                 data=datetime_to_numeric(\n                     x.data,\n-                    offset=np.datetime64(\"1970-01-01\"),\n+                    offset=offset,\n                     datetime_unit=\"ns\",\n                 ),\n             )\n", "model": "claude-haiku-5-5", "steps": 10, "finished": true, "patch_lines": 22, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 22, "steps": 10}], "ms": 14733}
{"instance_id": "pydata__xarray-6721", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/common.py b/xarray/core/common.py\nindex 3c328f42..40819a42 100644\n--- a/xarray/core/common.py\n+++ b/xarray/core/common.py\n@@ -2023,7 +2023,9 @@ def get_chunksizes(\n \n     chunks: dict[Any, tuple[int, ...]] = {}\n     for v in variables:\n-        if hasattr(v.data, \"chunks\"):\n+        # use v.chunks (which inspects the underlying _data) rather than v.data,\n+        # because v.data loads lazily-indexed (e.g. zarr/netCDF) arrays into memory\n+        if v.chunks is not None:\n             for dim, c in v.chunksizes.items():\n                 if dim in chunks and c != chunks[dim]:\n                     raise ValueError(\n", "model": "claude-haiku-5-5", "steps": 10, "finished": true, "patch_lines": 15, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 15, "steps": 10}], "ms": 13175}
{"instance_id": "pydata__xarray-6744", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py\nindex aef290f6..75116d7f 100644\n--- a/xarray/core/rolling.py\n+++ b/xarray/core/rolling.py\n@@ -270,9 +270,12 @@ class DataArrayRolling(Rolling[\"DataArray\"]):\n     def __iter__(self) -> Iterator[tuple[RollingKey, DataArray]]:\n         if self.ndim > 1:\n             raise ValueError(\"__iter__ is only supported for 1d-rolling\")\n-        stops = np.arange(1, len(self.window_labels) + 1)\n-        starts = stops - int(self.window[0])\n-        starts[: int(self.window[0])] = 0\n+        window0 = int(self.window[0])\n+        # for center=True, the window for label i is centered on i, i.e. it\n+        # ends at i + (window - 1) // 2 (inclusive), matching the reduce path\n+        offset = (window0 - 1) // 2 if self.center[0] else 0\n+        stops = np.arange(1, len(self.window_labels) + 1) + offset\n+        starts = np.maximum(stops - window0, 0)\n         for (label, start, stop) in zip(self.window_labels, starts, stops):\n             window = self.obj.isel({self.dim[0]: slice(start, stop)})\n \n", "model": "claude-haiku-5-5", "steps": 9, "finished": false, "patch_lines": 20, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 20, "steps": 9}], "ms": 48309}
{"instance_id": "pydata__xarray-6938", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py\nindex c775d05c..09db4f4d 100644\n--- a/xarray/core/dataset.py\n+++ b/xarray/core/dataset.py\n@@ -3772,8 +3772,11 @@ class Dataset(\n         for k, v in self.variables.items():\n             dims = tuple(dims_dict.get(dim, dim) for dim in v.dims)\n             if k in result_dims:\n-                var = v.to_index_variable()\n-                var.dims = dims\n+                # build a new object: to_index_variable() may return ``v``\n+                # itself, and mutating its dims would modify the original\n+                var = IndexVariable(\n+                    dims, v._data, v._attrs, encoding=v._encoding, fastpath=True\n+                )\n                 if k in self._indexes:\n                     indexes[k] = self._indexes[k]\n                     variables[k] = var\n", "model": "claude-haiku-5-5", "steps": 12, "finished": false, "patch_lines": 18, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 18, "steps": 12}], "ms": 18194}
{"instance_id": "pydata__xarray-6992", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py\nindex 620f32f8..441c1698 100644\n--- a/xarray/core/dataset.py\n+++ b/xarray/core/dataset.py\n@@ -4177,7 +4177,7 @@ class Dataset(\n         }\n         variables.update(new_variables)\n \n-        coord_names = set(new_variables) | self._coord_names\n+        coord_names = (set(new_variables) | self._coord_names) - set(drop_variables)\n \n         return self._replace(variables, coord_names=coord_names, indexes=indexes)\n \n", "model": "claude-haiku-5-5", "steps": 5, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 13, "steps": 5}], "ms": 12671}
{"instance_id": "pydata__xarray-7229", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/computation.py b/xarray/core/computation.py\nindex 3f7e8f74..f1a3e4b2 100644\n--- a/xarray/core/computation.py\n+++ b/xarray/core/computation.py\n@@ -1860,7 +1860,12 @@ def where(cond, x, y, keep_attrs=None):\n     if keep_attrs is True:\n         # keep the attributes of x, the second parameter, by default to\n         # be consistent with the `where` method of `DataArray` and `Dataset`\n-        keep_attrs = lambda attrs, context: getattr(x, \"attrs\", {})\n+        # Only xarray-like arguments contribute attrs, so ``x`` is the second\n+        # entry only if ``cond`` also carries attrs.\n+        x_pos = 1 if hasattr(cond, \"attrs\") else 0\n+        keep_attrs = lambda attrs, context: (\n+            attrs[x_pos] if len(attrs) > x_pos else (attrs[-1] if attrs else {})\n+        )\n \n     # alignment for three arguments is complicated, so don't support it yet\n     return apply_ufunc(\n", "model": "claude-sonnet-5-5", "steps": 8, "finished": true, "patch_lines": 18, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 18, "steps": 8}], "ms": 60847}
{"instance_id": "pydata__xarray-7233", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py\nindex c194ec08..968daae8 100644\n--- a/xarray/core/rolling.py\n+++ b/xarray/core/rolling.py\n@@ -973,7 +973,7 @@ class Coarsen(CoarsenArithmetic, Generic[T_Xarray]):\n             else:\n                 reshaped[key] = var\n \n-        should_be_coords = set(window_dim) & set(self.obj.coords)\n+        should_be_coords = set(self.obj.coords) & set(reshaped.variables)\n         result = reshaped.set_coords(should_be_coords)\n         if isinstance(self.obj, DataArray):\n             return self.obj._from_temp_dataset(result)\n", "model": "claude-sonnet-5-5", "steps": 8, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 13, "steps": 8}], "ms": 16207}
