@@ -296,6 +296,22 @@ def _merge_chunk_array(
296
296
is_complete_chunk : bool ,
297
297
drop_axes : tuple [int , ...],
298
298
) -> NDBuffer :
299
+ if (
300
+ is_complete_chunk
301
+ and value .shape == chunk_spec .shape
302
+ # Guard that this is not a partial chunk at the end with is_complete_chunk=True
303
+ and value [out_selection ].shape == chunk_spec .shape
304
+ ):
305
+ return value
306
+ if existing_chunk_array is None :
307
+ chunk_array = chunk_spec .prototype .nd_buffer .create (
308
+ shape = chunk_spec .shape ,
309
+ dtype = chunk_spec .dtype .to_native_dtype (),
310
+ order = chunk_spec .order ,
311
+ fill_value = fill_value_or_default (chunk_spec ),
312
+ )
313
+ else :
314
+ chunk_array = existing_chunk_array .copy () # make a writable copy
299
315
if chunk_selection == () or is_scalar (
300
316
value .as_ndarray_like (), chunk_spec .dtype .to_native_dtype ()
301
317
):
@@ -311,20 +327,6 @@ def _merge_chunk_array(
311
327
for idx in range (chunk_spec .ndim )
312
328
)
313
329
chunk_value = chunk_value [item ]
314
- if is_complete_chunk and chunk_value .shape == chunk_spec .shape :
315
- # TODO: For the last chunk, we could have is_complete_chunk=True
316
- # that is smaller than the chunk_spec.shape but this throws
317
- # an error in the _decode_single
318
- return chunk_value .copy () # make a writable copy
319
- if existing_chunk_array is None :
320
- chunk_array = chunk_spec .prototype .nd_buffer .create (
321
- shape = chunk_spec .shape ,
322
- dtype = chunk_spec .dtype .to_native_dtype (),
323
- order = chunk_spec .order ,
324
- fill_value = fill_value_or_default (chunk_spec ),
325
- )
326
- else :
327
- chunk_array = existing_chunk_array .copy () # make a writable copy
328
330
chunk_array [chunk_selection ] = chunk_value
329
331
return chunk_array
330
332
0 commit comments