Skip to content

Commit 6047a8c

Browse files
committed
DEPR: join_axes-kwarg in pd.concat
1 parent 0370740 commit 6047a8c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ Deprecations
479479
- :meth:`Series.ptp` is deprecated. Use ``numpy.ptp`` instead (:issue:`21614`)
480480
- :meth:`Series.compress` is deprecated. Use ``Series[condition]`` instead (:issue:`18262`)
481481
- :meth:`Categorical.from_codes` has deprecated providing float values for the ``codes`` argument. (:issue:`21767`)
482+
- :meth:`pandas.concat` has deprecated the ``join_axes``-keyword. Instead, use :meth:`DataFrame.reindex` or :meth:`DataFrame.reindex_like` on the result (:issue:`21951`)
482483
- :func:`pandas.read_table` is deprecated. Instead, use :func:`pandas.read_csv` passing ``sep='\t'`` if necessary (:issue:`21948`)
483484

484485
.. _whatsnew_0240.prior_deprecations:

pandas/core/reshape/concat.py

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import pandas.core.indexes.base as ibase
1515
from pandas.core.generic import NDFrame
1616
import pandas.core.dtypes.concat as _concat
17+
import warnings
1718

1819
# ---------------------------------------------------------------------
1920
# Concatenate DataFrame objects
@@ -219,6 +220,11 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
219220
...
220221
ValueError: Indexes have overlapping values: ['a']
221222
"""
223+
if join_axes is not None:
224+
warnings.warn('The join_axes-keyword is deprecated. Use .reindex or '
225+
'.reindex_like on the result to achieve the same '
226+
'functionality, or apply those methods to the inputs if '
227+
'performance-sensitive.', FutureWarning, stacklevel=2)
222228
op = _Concatenator(objs, axis=axis, join_axes=join_axes,
223229
ignore_index=ignore_index, join=join,
224230
keys=keys, levels=levels, names=names,

pandas/tests/reshape/test_concat.py

+19
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,25 @@ def test_concat_categorical_empty(self):
729729
tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp)
730730
tm.assert_series_equal(s2.append(s1, ignore_index=True), exp)
731731

732+
def test_concat_join_axes(self, axis):
733+
one = pd.DataFrame([[0., 1.], [2., 3.]], columns=list('ab'))
734+
two = pd.DataFrame([[10., 11.], [12., 13.]], index=[1, 2],
735+
columns=list('bc'))
736+
737+
expected = pd.concat([one, two],
738+
axis=1, sort=False).reindex(index=two.index)
739+
with tm.assert_produces_warning(expected_warning=FutureWarning):
740+
result = pd.concat([one, two],
741+
axis=1, sort=False, join_axes=[two.index])
742+
tm.assert_frame_equal(result, expected)
743+
744+
expected = pd.concat([one, two],
745+
axis=0, sort=False).reindex(columns=two.columns)
746+
with tm.assert_produces_warning(expected_warning=FutureWarning):
747+
result = pd.concat([one, two],
748+
axis=0, sort=False, join_axes=[two.columns])
749+
tm.assert_frame_equal(result, expected)
750+
732751

733752
class TestAppend(ConcatenateBase):
734753

0 commit comments

Comments
 (0)