diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 38682d188e57a..574f089450998 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -701,6 +701,7 @@ Deprecations - Deprecated passing arguments as positional (other than ``filepath_or_buffer``) in :func:`read_csv` (:issue:`41485`) - Deprecated passing arguments as positional in :meth:`DataFrame.drop` (other than ``"labels"``) and :meth:`Series.drop` (:issue:`41485`) - Deprecated passing arguments as positional (other than ``filepath_or_buffer``) in :func:`read_table` (:issue:`41485`) +- Deprecated passing arguments as positional (other than ``objs``) in :func:`concat` (:issue:`41485`) .. _whatsnew_130.deprecations.nuisance_columns: diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index b3b453ea6355a..804418d3c4d89 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -16,7 +16,10 @@ import numpy as np from pandas._typing import FrameOrSeriesUnion -from pandas.util._decorators import cache_readonly +from pandas.util._decorators import ( + cache_readonly, + deprecate_nonkeyword_arguments, +) from pandas.core.dtypes.concat import concat_compat from pandas.core.dtypes.generic import ( @@ -52,6 +55,7 @@ # Concatenate DataFrame objects +@deprecate_nonkeyword_arguments(version=None, allowed_args=["objs"]) @overload def concat( objs: Iterable[DataFrame] | Mapping[Hashable, DataFrame], diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index 96b88dc61cfed..57b0462710bc5 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -638,3 +638,20 @@ def test_concat_multiindex_with_empty_rangeindex(): result = concat([df1, df2]) expected = DataFrame([[1, 2], [np.nan, np.nan]], columns=mi) tm.assert_frame_equal(result, expected) + + +def test_concat_posargs_deprecation(all_parsers): + # https://github.com/pandas-dev/pandas/issues/41485 + df = pd.DataFrame([[1,2,3]], index=["a"]) + df2 = pd.DataFrame([[4,5,6]], index=["b"]) + + msg = ( + "In a future version of pandas all arguments of concat" + "except for the argument 'objs' will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + concat([df, df2], " ") + expected = DataFrame([[1,2,3],[4,5,6]], index=["a","b"]) + tm.assert_frame_equal(result, expected) + +