File tree 3 files changed +18
-0
lines changed
3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -4840,6 +4840,8 @@ def _reindex_axes(
4840
4840
copy = copy ,
4841
4841
allow_dups = False ,
4842
4842
)
4843
+ # If we've made a copy once, no need to make another one
4844
+ copy = False
4843
4845
4844
4846
return obj
4845
4847
Original file line number Diff line number Diff line change @@ -601,6 +601,8 @@ def _reindex_indexer(
601
601
)
602
602
else :
603
603
arr = self .arrays [i ]
604
+ if copy :
605
+ arr = arr .copy ()
604
606
new_arrays .append (arr )
605
607
606
608
else :
Original file line number Diff line number Diff line change @@ -83,6 +83,20 @@ class TestDataFrameSelectReindex:
83
83
# These are specific reindex-based tests; other indexing tests should go in
84
84
# test_indexing
85
85
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
+
86
100
def test_reindex_date_fill_value (self ):
87
101
# passing date to dt64 is deprecated
88
102
arr = date_range ("2016-01-01" , periods = 6 ).values .reshape (3 , 2 )
You can’t perform that action at this time.
0 commit comments