File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -4840,6 +4840,8 @@ def _reindex_axes(
48404840 copy = copy ,
48414841 allow_dups = False ,
48424842 )
4843+ # If we've made a copy once, no need to make another one
4844+ copy = False
48434845
48444846 return obj
48454847
Original file line number Diff line number Diff line change @@ -601,6 +601,8 @@ def _reindex_indexer(
601601 )
602602 else :
603603 arr = self .arrays [i ]
604+ if copy :
605+ arr = arr .copy ()
604606 new_arrays .append (arr )
605607
606608 else :
Original file line number Diff line number Diff line change @@ -83,6 +83,20 @@ class TestDataFrameSelectReindex:
8383 # These are specific reindex-based tests; other indexing tests should go in
8484 # test_indexing
8585
86+ def test_reindex_copies (self ):
87+ # based on asv time_reindex_axis1
88+ N = 10
89+ df = DataFrame (np .random .randn (N * 10 , N ))
90+ cols = np .arange (N )
91+ np .random .shuffle (cols )
92+
93+ result = df .reindex (columns = cols , copy = True )
94+ assert not np .shares_memory (result [0 ]._values , df [0 ]._values )
95+
96+ # pass both columns and index
97+ result2 = df .reindex (columns = cols , index = df .index , copy = True )
98+ assert not np .shares_memory (result2 [0 ]._values , df [0 ]._values )
99+
86100 def test_reindex_date_fill_value (self ):
87101 # passing date to dt64 is deprecated
88102 arr = date_range ("2016-01-01" , periods = 6 ).values .reshape (3 , 2 )
You can’t perform that action at this time.
0 commit comments