@@ -666,7 +666,7 @@ def _sort_labels(uniques, left, right):
666
666
667
667
668
668
def concat (objs , axis = 0 , join = 'outer' , join_axes = None , ignore_index = False ,
669
- keys = None , levels = None , names = None , verify_integrity = False ):
669
+ keys = None , levels = None , names = None , verify_integrity = False , copy = True ):
670
670
"""
671
671
Concatenate pandas objects along a particular axis with optional set logic
672
672
along the other axes. Can also add a layer of hierarchical indexing on the
@@ -704,6 +704,8 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
704
704
concatenating objects where the concatenation axis does not have
705
705
meaningful indexing information. Note the the index values on the other
706
706
axes are still respected in the join.
707
+ copy : boolean, default True
708
+ If False, do not copy data unnecessarily
707
709
708
710
Notes
709
711
-----
@@ -716,7 +718,8 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
716
718
op = _Concatenator (objs , axis = axis , join_axes = join_axes ,
717
719
ignore_index = ignore_index , join = join ,
718
720
keys = keys , levels = levels , names = names ,
719
- verify_integrity = verify_integrity )
721
+ verify_integrity = verify_integrity ,
722
+ copy = copy )
720
723
return op .get_result ()
721
724
722
725
@@ -727,7 +730,7 @@ class _Concatenator(object):
727
730
728
731
def __init__ (self , objs , axis = 0 , join = 'outer' , join_axes = None ,
729
732
keys = None , levels = None , names = None ,
730
- ignore_index = False , verify_integrity = False ):
733
+ ignore_index = False , verify_integrity = False , copy = True ):
731
734
if not isinstance (objs , (list ,tuple ,types .GeneratorType ,dict ,TextFileReader )):
732
735
raise TypeError ('first argument must be a list-like of pandas '
733
736
'objects, you passed an object of type '
@@ -846,6 +849,7 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
846
849
847
850
self .ignore_index = ignore_index
848
851
self .verify_integrity = verify_integrity
852
+ self .copy = copy
849
853
850
854
self .new_axes = self ._get_new_axes ()
851
855
@@ -879,7 +883,9 @@ def get_result(self):
879
883
mgrs_indexers .append ((obj ._data , indexers ))
880
884
881
885
new_data = concatenate_block_managers (
882
- mgrs_indexers , self .new_axes , concat_axis = self .axis , copy = True )
886
+ mgrs_indexers , self .new_axes , concat_axis = self .axis , copy = self .copy )
887
+ if not self .copy :
888
+ new_data ._consolidate_inplace ()
883
889
884
890
return self .objs [0 ]._from_axes (new_data , self .new_axes ).__finalize__ (self , method = 'concat' )
885
891
0 commit comments