@@ -1558,7 +1558,24 @@ def _set_selection(self, indexer, value, fields=None):
1558
1558
self ._chunk_setitem (chunk_coords , chunk_selection , chunk_value , fields = fields )
1559
1559
else :
1560
1560
lchunk_coords , lchunk_selection , lout_selection = zip (* indexer )
1561
- self ._chunk_setitems (lchunk_coords , lchunk_selection , out , lout_selection ,
1561
+ chunk_values = []
1562
+ for out_selection in lout_selection :
1563
+ if sel_shape == ():
1564
+ chunk_values .append (value )
1565
+ elif is_scalar (value , self ._dtype ):
1566
+ chunk_values .append (value )
1567
+ else :
1568
+ cv = value [out_selection ]
1569
+ # handle missing singleton dimensions
1570
+ if indexer .drop_axes :
1571
+ item = [slice (None )] * self .ndim
1572
+ for a in indexer .drop_axes :
1573
+ item [a ] = np .newaxis
1574
+ item = tuple (item )
1575
+ cv = chunk_value [item ]
1576
+ chunk_values .append (cv )
1577
+
1578
+ self ._chunk_setitems (lchunk_coords , lchunk_selection , chunk_values ,
1562
1579
fields = fields )
1563
1580
1564
1581
def _process_chunk (self , out , cdata , chunk_selection , drop_axes ,
@@ -1683,6 +1700,12 @@ def _chunk_getitems(self, lchunk_coords, lchunk_selection, out, lout_selection,
1683
1700
fill_value = self ._fill_value
1684
1701
out [out_select ] = fill_value
1685
1702
1703
+ def _chunk_setitems (self , lchunk_coords , lchunk_selection , values , fields = None ):
1704
+ ckeys = [self ._chunk_key (co ) for co in lchunk_coords ]
1705
+ cdatas = [self ._process_for_setitem (sel , val , fields = fields )
1706
+ for sel , val in zip (lchunk_selection , values )]
1707
+ self .chunk_store .setitems ({k : v for k , v in zip (ckeys , cdatas )})
1708
+
1686
1709
def _chunk_setitem (self , chunk_coords , chunk_selection , value , fields = None ):
1687
1710
"""Replace part or whole of a chunk.
1688
1711
@@ -1710,10 +1733,12 @@ def _chunk_setitem(self, chunk_coords, chunk_selection, value, fields=None):
1710
1733
fields = fields )
1711
1734
1712
1735
def _chunk_setitem_nosync (self , chunk_coords , chunk_selection , value , fields = None ):
1713
-
1714
- # obtain key for chunk storage
1715
1736
ckey = self ._chunk_key (chunk_coords )
1737
+ cdata = self ._process_for_setitem (chunk_selection , value , fields = fields )
1738
+ # store
1739
+ self .chunk_store [ckey ] = cdata
1716
1740
1741
+ def _process_for_setitem (self , chunk_selection , value , fields = None ):
1717
1742
if is_total_slice (chunk_selection , self ._chunks ) and not fields :
1718
1743
# totally replace chunk
1719
1744
@@ -1768,10 +1793,7 @@ def _chunk_setitem_nosync(self, chunk_coords, chunk_selection, value, fields=Non
1768
1793
chunk [chunk_selection ] = value
1769
1794
1770
1795
# encode chunk
1771
- cdata = self ._encode_chunk (chunk )
1772
-
1773
- # store
1774
- self .chunk_store [ckey ] = cdata
1796
+ return self ._encode_chunk (chunk )
1775
1797
1776
1798
def _chunk_key (self , chunk_coords ):
1777
1799
return self ._key_prefix + '.' .join (map (str , chunk_coords ))
0 commit comments