(self, ds, region)
| 1355 | self.zarr_group.store.close() |
| 1356 | |
| 1357 | def _auto_detect_regions(self, ds, region): |
| 1358 | for dim, val in region.items(): |
| 1359 | if val != "auto": |
| 1360 | continue |
| 1361 | |
| 1362 | if dim not in ds._variables: |
| 1363 | # unindexed dimension |
| 1364 | region[dim] = slice(0, ds.sizes[dim]) |
| 1365 | continue |
| 1366 | |
| 1367 | variable = conventions.decode_cf_variable( |
| 1368 | dim, self.open_store_variable(dim).compute() |
| 1369 | ) |
| 1370 | assert variable.dims == (dim,) |
| 1371 | index = pd.Index(variable.data) |
| 1372 | idxs = index.get_indexer(ds[dim].data) |
| 1373 | if (idxs == -1).any(): |
| 1374 | raise KeyError( |
| 1375 | f"Not all values of coordinate '{dim}' in the new array were" |
| 1376 | " found in the original store. Writing to a zarr region slice" |
| 1377 | " requires that no dimensions or metadata are changed by the write." |
| 1378 | ) |
| 1379 | |
| 1380 | if (np.diff(idxs) != 1).any(): |
| 1381 | raise ValueError( |
| 1382 | f"The auto-detected region of coordinate '{dim}' for writing new data" |
| 1383 | " to the original store had non-contiguous indices. Writing to a zarr" |
| 1384 | " region slice requires that the new data constitute a contiguous subset" |
| 1385 | " of the original store." |
| 1386 | ) |
| 1387 | region[dim] = slice(idxs[0], idxs[-1] + 1) |
| 1388 | return region |
| 1389 | |
| 1390 | def _validate_and_autodetect_region(self, ds: Dataset) -> Dataset: |
| 1391 | if self._write_region is None: |
no test coverage detected