@@ -308,12 +308,14 @@ def write(
308308 """
309309
310310 write_options : Union [TileDBCreateOptions , TileDBWriteOptions ]
311+ sort_coords = None
311312 if isinstance (platform_config , TileDBCreateOptions ):
312313 raise ValueError (
313314 "As of TileDB-SOMA 1.13, the write method takes "
314315 "TileDBWriteOptions instead of TileDBCreateOptions"
315316 )
316317 write_options = TileDBWriteOptions .from_platform_config (platform_config )
318+ sort_coords = write_options .sort_coords
317319
318320 clib_sparse_array = self ._handle ._handle
319321
@@ -322,14 +324,6 @@ def write(
322324 data , coords = values .to_numpy ()
323325
324326 mq = ManagedQuery (self , platform_config )
325-
326- layout = (
327- clib .ResultOrder .unordered
328- if write_options .sort_coords
329- else clib .ResultOrder .globalorder
330- )
331- mq ._handle .set_layout (layout )
332-
333327 for i , c in enumerate (coords .T ):
334328 mq ._handle .set_column_data (
335329 f"soma_dim_{ i } " ,
@@ -344,12 +338,7 @@ def write(
344338 data , dtype = self .schema .field ("soma_data" ).type .to_pandas_dtype ()
345339 ),
346340 )
347-
348- if layout == clib .ResultOrder .unordered :
349- mq ._handle .submit_write ()
350- mq ._handle .finalize ()
351- else :
352- mq ._handle .submit_and_finalize ()
341+ mq ._handle .submit_write (sort_coords or True )
353342
354343 if write_options .consolidate_and_vacuum :
355344 # Consolidate non-bulk data
@@ -366,14 +355,6 @@ def write(
366355 sp = values .to_scipy ().tocoo ()
367356
368357 mq = ManagedQuery (self , platform_config )
369-
370- layout = (
371- clib .ResultOrder .unordered
372- if write_options .sort_coords
373- else clib .ResultOrder .globalorder
374- )
375- mq ._handle .set_layout (layout )
376-
377358 for i , c in enumerate ([sp .row , sp .col ]):
378359 mq ._handle .set_column_data (
379360 f"soma_dim_{ i } " ,
@@ -388,20 +369,20 @@ def write(
388369 sp .data , dtype = self .schema .field ("soma_data" ).type .to_pandas_dtype ()
389370 ),
390371 )
391-
392- if layout == clib .ResultOrder .unordered :
393- mq ._handle .submit_write ()
394- mq ._handle .finalize ()
395- else :
396- mq ._handle .submit_and_finalize ()
372+ mq ._handle .submit_write (sort_coords or True )
397373
398374 if write_options .consolidate_and_vacuum :
399375 # Consolidate non-bulk data
400376 clib_sparse_array .consolidate_and_vacuum ()
401377 return self
402378
403379 if isinstance (values , pa .Table ):
404- self ._write_table (values , write_options .sort_coords )
380+ # Write bulk data
381+ for batch in values .to_batches ():
382+ # clib_sparse_array.write(batch, sort_coords or False)
383+ mq = ManagedQuery (self , None )
384+ mq ._handle .set_array_data (batch )
385+ mq ._handle .submit_write (sort_coords or False )
405386
406387 if write_options .consolidate_and_vacuum :
407388 # Consolidate non-bulk data
0 commit comments