@@ -1572,14 +1572,11 @@ def _validate_and_autodetect_region(
1572
1572
raise TypeError (f"``region`` must be a dict, got { type (region )} " )
1573
1573
1574
1574
if any (v == "auto" for v in region .values ()):
1575
- region_was_autodetected = True
1576
1575
if mode != "r+" :
1577
1576
raise ValueError (
1578
1577
f"``mode`` must be 'r+' when using ``region='auto'``, got { mode } "
1579
1578
)
1580
1579
region = _auto_detect_regions (ds , region , open_kwargs )
1581
- else :
1582
- region_was_autodetected = False
1583
1580
1584
1581
for k , v in region .items ():
1585
1582
if k not in ds .dims :
@@ -1612,7 +1609,7 @@ def _validate_and_autodetect_region(
1612
1609
f".drop_vars({ non_matching_vars !r} )"
1613
1610
)
1614
1611
1615
- return region , region_was_autodetected
1612
+ return region
1616
1613
1617
1614
1618
1615
def _validate_datatypes_for_zarr_append (zstore , dataset ):
@@ -1784,12 +1781,9 @@ def to_zarr(
1784
1781
storage_options = storage_options ,
1785
1782
zarr_version = zarr_version ,
1786
1783
)
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 )
1793
1787
if append_dim is not None and append_dim in region :
1794
1788
raise ValueError (
1795
1789
f"cannot list the same dimension in both ``append_dim`` and "
0 commit comments