diff --git a/doc/source/whatsnew/v0.17.0.rst b/doc/source/whatsnew/v0.17.0.rst index d8f39a7d6e3c0..991b9a40d151b 100644 --- a/doc/source/whatsnew/v0.17.0.rst +++ b/doc/source/whatsnew/v0.17.0.rst @@ -423,7 +423,7 @@ Other enhancements .. code-block:: ipython - In [1]: pd.concat([foo, bar, baz], 1) + In [1]: pd.concat([foo, bar, baz], axis=1) Out[1]: 0 1 2 0 1 1 4 @@ -433,7 +433,7 @@ Other enhancements .. ipython:: python - pd.concat([foo, bar, baz], 1) + pd.concat([foo, bar, baz], axis=1) - ``DataFrame`` has gained the ``nlargest`` and ``nsmallest`` methods (:issue:`10393`) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index ce613fd78c1e1..55e8196754fdb 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -711,6 +711,7 @@ Deprecations - Deprecated passing lists as ``key`` to :meth:`DataFrame.xs` and :meth:`Series.xs` (:issue:`41760`) - 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..ea34bc75b4e31 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 ( @@ -84,6 +87,7 @@ def concat( ... +@deprecate_nonkeyword_arguments(version=None, allowed_args=["objs"]) def concat( objs: Iterable[NDFrame] | Mapping[Hashable, NDFrame], axis=0, diff --git a/pandas/io/stata.py b/pandas/io/stata.py index e4f3bcb89cf7e..1fef33558dd9a 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -1762,7 +1762,7 @@ def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFra columns = data.columns replacement_df = DataFrame(replacements) replaced = concat( - [data.drop(replacement_df.columns, axis=1), replacement_df], 1 + [data.drop(replacement_df.columns, axis=1), replacement_df], axis=1 ) data = replaced[columns] return data diff --git a/pandas/tests/io/pytables/test_complex.py b/pandas/tests/io/pytables/test_complex.py index 8e1dee5873512..6cfe80ae5c87c 100644 --- a/pandas/tests/io/pytables/test_complex.py +++ b/pandas/tests/io/pytables/test_complex.py @@ -205,4 +205,4 @@ def test_complex_append(setup_path): store.append("df", df, data_columns=["b"]) store.append("df", df) result = store.select("df") - tm.assert_frame_equal(pd.concat([df, df], 0), result) + tm.assert_frame_equal(pd.concat([df, df], axis=0), result) diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index 96b88dc61cfed..17a7089f0ac85 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -638,3 +638,18 @@ 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(): + # https://github.com/pandas-dev/pandas/issues/41485 + df = DataFrame([[1, 2, 3]], index=["a"]) + df2 = 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): + result = concat([df, df2], 0) + expected = DataFrame([[1, 2, 3], [4, 5, 6]], index=["a", "b"]) + tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/reshape/concat/test_invalid.py b/pandas/tests/reshape/concat/test_invalid.py index 95a81ce61c785..cd2a7ca33a267 100644 --- a/pandas/tests/reshape/concat/test_invalid.py +++ b/pandas/tests/reshape/concat/test_invalid.py @@ -27,13 +27,12 @@ def test_concat_invalid(self): def test_concat_invalid_first_argument(self): df1 = tm.makeCustomDataframe(10, 2) - df2 = tm.makeCustomDataframe(10, 2) msg = ( "first argument must be an iterable of pandas " 'objects, you passed an object of type "DataFrame"' ) with pytest.raises(TypeError, match=msg): - concat(df1, df2) + concat(df1) # generator ok though concat(DataFrame(np.random.rand(5, 5)) for _ in range(3))