From 5294371c59891d7050ff51a77c22b7017046d283 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Wed, 22 Aug 2018 23:07:11 +0200 Subject: [PATCH] Review (jreback) --- pandas/core/frame.py | 7 ++++--- pandas/core/generic.py | 3 ++- pandas/core/groupby/generic.py | 7 ++++--- pandas/core/reshape/concat.py | 3 +-- pandas/tests/reshape/test_concat.py | 3 ++- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 11d831bb0bad93..83fd882ae302ee 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6507,9 +6507,10 @@ def _join_compat(self, other, on=None, how='left', lsuffix='', rsuffix='', # join indexes only using concat if can_concat: if how == 'left': - how = 'outer' - return concat(frames, axis=1, join=how, - verify_integrity=True).reindex(self.index) + res = concat(frames, axis=1, join='outer', + verify_integrity=True, copy=False) + res = res.reindex(self.index, copy=False) + return res else: return concat(frames, axis=1, join=how, verify_integrity=True) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6b84c02de3e1ce..f0b7941f64b0c9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8931,7 +8931,8 @@ def describe_1d(data): if name not in names: names.append(name) - d = pd.concat([x.reindex(names) for x in ldesc], axis=1, sort=False) + d = pd.concat([x.reindex(names) for x in ldesc], axis=1, + sort=False, copy=False) d.columns = data.columns.copy() return d diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 7c64c8d9424ca7..7b7476f8c4dfc4 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -518,10 +518,11 @@ def _transform_general(self, func, *args, **kwargs): applied.append(res) concat_index = obj.columns if self.axis == 0 else obj.index - other_axis = (self.axis + 1) % 2 # switches from 0 to 1 or from 1 to 0 + other_axis = 1 if self.axis == 0 else 0 # switches between 0 & 1 concatenated = concat(applied, axis=self.axis, - verify_integrity=False).reindex(concat_index, - axis=other_axis) + verify_integrity=False, copy=False) + concatenated = concatenated.reindex(concat_index, axis=other_axis, + copy=False) return self._set_result_index_ordered(concatenated) @Substitution(klass='DataFrame', selected='') diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 3d79f3ee51f22c..949a6e66e4dc6c 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -223,8 +223,7 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False, if join_axes is not None: warnings.warn('The join_axes-keyword is deprecated. Use .reindex or ' '.reindex_like on the result to achieve the same ' - 'functionality, or apply those methods to the inputs if ' - 'performance-sensitive.', FutureWarning, stacklevel=2) + 'functionality.', FutureWarning, stacklevel=2) op = _Concatenator(objs, axis=axis, join_axes=join_axes, ignore_index=ignore_index, join=join, keys=keys, levels=levels, names=names, diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index 0a427f37e1784d..2e726b8a7679ac 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -729,7 +729,8 @@ def test_concat_categorical_empty(self): tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) - def test_concat_join_axes(self, axis): + def test_concat_join_axes_deprecated(self, axis): + # GH21951 one = pd.DataFrame([[0., 1.], [2., 3.]], columns=list('ab')) two = pd.DataFrame([[10., 11.], [12., 13.]], index=[1, 2], columns=list('bc'))