Skip to content

Commit cee2914

Browse files
committed
Don't allow overwriting indexes with region writes
Closes pydata#8589
1 parent 6af547c commit cee2914

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

xarray/backends/api.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,14 +1572,11 @@ def _validate_and_autodetect_region(
15721572
raise TypeError(f"``region`` must be a dict, got {type(region)}")
15731573

15741574
if any(v == "auto" for v in region.values()):
1575-
region_was_autodetected = True
15761575
if mode != "r+":
15771576
raise ValueError(
15781577
f"``mode`` must be 'r+' when using ``region='auto'``, got {mode}"
15791578
)
15801579
region = _auto_detect_regions(ds, region, open_kwargs)
1581-
else:
1582-
region_was_autodetected = False
15831580

15841581
for k, v in region.items():
15851582
if k not in ds.dims:
@@ -1612,7 +1609,7 @@ def _validate_and_autodetect_region(
16121609
f".drop_vars({non_matching_vars!r})"
16131610
)
16141611

1615-
return region, region_was_autodetected
1612+
return region
16161613

16171614

16181615
def _validate_datatypes_for_zarr_append(zstore, dataset):
@@ -1784,12 +1781,9 @@ def to_zarr(
17841781
storage_options=storage_options,
17851782
zarr_version=zarr_version,
17861783
)
1787-
region, region_was_autodetected = _validate_and_autodetect_region(
1788-
dataset, region, mode, open_kwargs
1789-
)
1790-
# drop indices to avoid potential race condition with auto region
1791-
if region_was_autodetected:
1792-
dataset = dataset.drop_vars(dataset.indexes)
1784+
region = _validate_and_autodetect_region(dataset, region, mode, open_kwargs)
1785+
# can't modify indexed with region writes
1786+
dataset = dataset.drop_vars(dataset.indexes)
17931787
if append_dim is not None and append_dim in region:
17941788
raise ValueError(
17951789
f"cannot list the same dimension in both ``append_dim`` and "

0 commit comments

Comments
 (0)