diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index fcd5cd0979252..598974979fefb 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -527,8 +527,8 @@ def copy_func(ax): if deep: new_arrays = [arr.copy() for arr in self.arrays] else: - new_arrays = self.arrays - return type(self)(new_arrays, new_axes) + new_arrays = list(self.arrays) + return type(self)(new_arrays, new_axes, verify_integrity=False) def reindex_indexer( self: T, diff --git a/pandas/core/internals/concat.py b/pandas/core/internals/concat.py index f14f3c4a38430..782842d167570 100644 --- a/pandas/core/internals/concat.py +++ b/pandas/core/internals/concat.py @@ -77,10 +77,16 @@ def _concatenate_array_managers( # reindex all arrays mgrs = [] for mgr, indexers in mgrs_indexers: + axis1_made_copy = False for ax, indexer in indexers.items(): mgr = mgr.reindex_indexer( axes[ax], indexer, axis=ax, allow_dups=True, use_na_proxy=True ) + if ax == 1 and indexer is not None: + axis1_made_copy = True + if copy and concat_axis == 0 and not axis1_made_copy: + # for concat_axis 1 we will always get a copy through concat_arrays + mgr = mgr.copy() mgrs.append(mgr) if concat_axis == 1: @@ -94,8 +100,6 @@ def _concatenate_array_managers( # concatting along the columns -> combine reindexed arrays in a single manager assert concat_axis == 0 arrays = list(itertools.chain.from_iterable([mgr.arrays for mgr in mgrs])) - if copy: - arrays = [x.copy() for x in arrays] new_mgr = ArrayManager(arrays, [axes[1], axes[0]], verify_integrity=False) return new_mgr