@@ -192,62 +192,60 @@ def _determine_zarr_chunks(
192192 # with chunk boundaries, then no synchronization is required."
193193 # TODO: incorporate synchronizer to allow writes from multiple dask
194194 # threads
195- if var_chunks and enc_chunks_tuple :
196- # If it is possible to write on partial chunks then it is not necessary to check
197- # the last one contained on the region
198- allow_partial_chunks = mode != "r+"
199-
200- base_error = (
201- f"Specified zarr chunks encoding['chunks']={ enc_chunks_tuple !r} for "
202- f"variable named { name !r} would overlap multiple dask chunks { var_chunks !r} "
203- f"on the region { region } . "
204- f"Writing this array in parallel with dask could lead to corrupted data. "
205- f"Consider either rechunking using `chunk()`, deleting "
206- f"or modifying `encoding['chunks']`, or specify `safe_chunks=False`."
207- )
208-
209- for zchunk , dchunks , interval , size in zip (
210- enc_chunks_tuple , var_chunks , region , shape , strict = True
211- ):
212- if not safe_chunks :
213- continue
214-
215- for dchunk in dchunks [1 :- 1 ]:
216- if dchunk % zchunk :
217- raise ValueError (base_error )
218-
219- region_start = interval .start if interval .start else 0
220-
221- if len (dchunks ) > 1 :
222- # The first border size is the amount of data that needs to be updated on the
223- # first chunk taking into account the region slice.
224- first_border_size = zchunk
225- if allow_partial_chunks :
226- first_border_size = zchunk - region_start % zchunk
227195
228- if (dchunks [0 ] - first_border_size ) % zchunk :
229- raise ValueError (base_error )
230-
231- if not allow_partial_chunks :
232- region_stop = interval .stop if interval .stop else size
233-
234- if region_start % zchunk :
235- # The last chunk which can also be the only one is a partial chunk
236- # if it is not aligned at the beginning
237- raise ValueError (base_error )
196+ # If it is possible to write on partial chunks then it is not necessary to check
197+ # the last one contained on the region
198+ allow_partial_chunks = mode != "r+"
199+
200+ base_error = (
201+ f"Specified zarr chunks encoding['chunks']={ enc_chunks_tuple !r} for "
202+ f"variable named { name !r} would overlap multiple dask chunks { var_chunks !r} "
203+ f"on the region { region } . "
204+ f"Writing this array in parallel with dask could lead to corrupted data. "
205+ f"Consider either rechunking using `chunk()`, deleting "
206+ f"or modifying `encoding['chunks']`, or specify `safe_chunks=False`."
207+ )
238208
239- if np .ceil (region_stop / zchunk ) == np .ceil (size / zchunk ):
240- # If the region is covering the last chunk then check
241- # if the reminder with the default chunk size
242- # is equal to the size of the last chunk
243- if dchunks [- 1 ] % zchunk != size % zchunk :
244- raise ValueError (base_error )
245- elif dchunks [- 1 ] % zchunk :
209+ for zchunk , dchunks , interval , size in zip (
210+ enc_chunks_tuple , var_chunks , region , shape , strict = True
211+ ):
212+ if not safe_chunks :
213+ continue
214+
215+ for dchunk in dchunks [1 :- 1 ]:
216+ if dchunk % zchunk :
217+ raise ValueError (base_error )
218+
219+ region_start = interval .start if interval .start else 0
220+
221+ if len (dchunks ) > 1 :
222+ # The first border size is the amount of data that needs to be updated on the
223+ # first chunk taking into account the region slice.
224+ first_border_size = zchunk
225+ if allow_partial_chunks :
226+ first_border_size = zchunk - region_start % zchunk
227+
228+ if (dchunks [0 ] - first_border_size ) % zchunk :
229+ raise ValueError (base_error )
230+
231+ if not allow_partial_chunks :
232+ region_stop = interval .stop if interval .stop else size
233+
234+ if region_start % zchunk :
235+ # The last chunk which can also be the only one is a partial chunk
236+ # if it is not aligned at the beginning
237+ raise ValueError (base_error )
238+
239+ if np .ceil (region_stop / zchunk ) == np .ceil (size / zchunk ):
240+ # If the region is covering the last chunk then check
241+ # if the reminder with the default chunk size
242+ # is equal to the size of the last chunk
243+ if dchunks [- 1 ] % zchunk != size % zchunk :
246244 raise ValueError (base_error )
245+ elif dchunks [- 1 ] % zchunk :
246+ raise ValueError (base_error )
247247
248- return enc_chunks_tuple
249-
250- raise AssertionError ("We should never get here. Function logic must be wrong." )
248+ return enc_chunks_tuple
251249
252250
253251def _get_zarr_dims_and_attrs (zarr_obj , dimension_key , try_nczarr ):
0 commit comments