@@ -649,6 +649,7 @@ def __init__(self, data_list, join_index, indexers, axis=1, copy=True):
649
649
for data , indexer in zip (data_list , indexers ):
650
650
if not data .is_consolidated ():
651
651
data = data .consolidate ()
652
+ data ._set_ref_locs ()
652
653
self .units .append (_JoinUnit (data .blocks , indexer ))
653
654
654
655
self .join_index = join_index
@@ -682,7 +683,6 @@ def get_result(self):
682
683
blockmaps = self ._prepare_blocks ()
683
684
kinds = _get_merge_block_kinds (blockmaps )
684
685
685
- result_is_unique = self .result_axes [0 ].is_unique
686
686
result_blocks = []
687
687
688
688
# maybe want to enable flexible copying <-- what did I mean?
@@ -692,23 +692,28 @@ def get_result(self):
692
692
if klass in mapping :
693
693
klass_blocks .extend ((unit , b ) for b in mapping [klass ])
694
694
res_blk = self ._get_merged_block (klass_blocks )
695
-
696
- # if we have a unique result index, need to clear the _ref_locs
697
- # a non-unique is set as we are creating
698
- if result_is_unique :
699
- res_blk .set_ref_locs (None )
700
-
701
695
result_blocks .append (res_blk )
702
696
703
697
return BlockManager (result_blocks , self .result_axes )
704
698
705
699
def _get_merged_block (self , to_merge ):
706
700
if len (to_merge ) > 1 :
701
+
702
+ # placement set here
707
703
return self ._merge_blocks (to_merge )
708
704
else :
709
705
unit , block = to_merge [0 ]
710
- return unit .reindex_block (block , self .axis ,
711
- self .result_items , copy = self .copy )
706
+ blk = unit .reindex_block (block , self .axis ,
707
+ self .result_items , copy = self .copy )
708
+
709
+ # set placement / invalidate on a unique result
710
+ if self .result_items .is_unique and blk ._ref_locs is not None :
711
+ if not self .copy :
712
+ blk = blk .copy ()
713
+ blk .set_ref_locs (None )
714
+
715
+ return blk
716
+
712
717
713
718
def _merge_blocks (self , merge_chunks ):
714
719
"""
@@ -736,7 +741,18 @@ def _merge_blocks(self, merge_chunks):
736
741
737
742
# does not sort
738
743
new_block_items = _concat_indexes ([b .items for _ , b in merge_chunks ])
739
- return make_block (out , new_block_items , self .result_items )
744
+
745
+ # need to set placement if we have a non-unique result
746
+ # calculate by the existing placement plus the offset in the result set
747
+ placement = None
748
+ if not self .result_items .is_unique :
749
+ nchunks = len (merge_chunks )
750
+ offsets = np .array ([0 ] + [ len (self .result_items ) / nchunks ] * (nchunks - 1 )).cumsum ()
751
+ placement = []
752
+ for (unit , blk ), offset in zip (merge_chunks ,offsets ):
753
+ placement .extend (blk .ref_locs + offset )
754
+
755
+ return make_block (out , new_block_items , self .result_items , placement = placement )
740
756
741
757
742
758
class _JoinUnit (object ):
0 commit comments