Skip to content

Commit a2c65df

Browse files
authored
DEPR: Deprecated passing arguments as positional in pd.concat (#41718)
1 parent e1e8f7a commit a2c65df

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed

doc/source/whatsnew/v0.17.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ Other enhancements
423423

424424
.. code-block:: ipython
425425
426-
In [1]: pd.concat([foo, bar, baz], 1)
426+
In [1]: pd.concat([foo, bar, baz], axis=1)
427427
Out[1]:
428428
0 1 2
429429
0 1 1 4
@@ -433,7 +433,7 @@ Other enhancements
433433

434434
.. ipython:: python
435435
436-
pd.concat([foo, bar, baz], 1)
436+
pd.concat([foo, bar, baz], axis=1)
437437
438438
- ``DataFrame`` has gained the ``nlargest`` and ``nsmallest`` methods (:issue:`10393`)
439439

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ Deprecations
711711
- Deprecated passing lists as ``key`` to :meth:`DataFrame.xs` and :meth:`Series.xs` (:issue:`41760`)
712712
- Deprecated passing arguments as positional in :meth:`DataFrame.drop` (other than ``"labels"``) and :meth:`Series.drop` (:issue:`41485`)
713713
- Deprecated passing arguments as positional (other than ``filepath_or_buffer``) in :func:`read_table` (:issue:`41485`)
714+
- Deprecated passing arguments as positional (other than ``objs``) in :func:`concat` (:issue:`41485`)
714715

715716

716717
.. _whatsnew_130.deprecations.nuisance_columns:

pandas/core/reshape/concat.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import numpy as np
1717

1818
from pandas._typing import FrameOrSeriesUnion
19-
from pandas.util._decorators import cache_readonly
19+
from pandas.util._decorators import (
20+
cache_readonly,
21+
deprecate_nonkeyword_arguments,
22+
)
2023

2124
from pandas.core.dtypes.concat import concat_compat
2225
from pandas.core.dtypes.generic import (
@@ -84,6 +87,7 @@ def concat(
8487
...
8588

8689

90+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["objs"])
8791
def concat(
8892
objs: Iterable[NDFrame] | Mapping[Hashable, NDFrame],
8993
axis=0,

pandas/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFra
17621762
columns = data.columns
17631763
replacement_df = DataFrame(replacements)
17641764
replaced = concat(
1765-
[data.drop(replacement_df.columns, axis=1), replacement_df], 1
1765+
[data.drop(replacement_df.columns, axis=1), replacement_df], axis=1
17661766
)
17671767
data = replaced[columns]
17681768
return data

pandas/tests/io/pytables/test_complex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,4 @@ def test_complex_append(setup_path):
205205
store.append("df", df, data_columns=["b"])
206206
store.append("df", df)
207207
result = store.select("df")
208-
tm.assert_frame_equal(pd.concat([df, df], 0), result)
208+
tm.assert_frame_equal(pd.concat([df, df], axis=0), result)

pandas/tests/reshape/concat/test_concat.py

+15
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,18 @@ def test_concat_multiindex_with_empty_rangeindex():
638638
result = concat([df1, df2])
639639
expected = DataFrame([[1, 2], [np.nan, np.nan]], columns=mi)
640640
tm.assert_frame_equal(result, expected)
641+
642+
643+
def test_concat_posargs_deprecation():
644+
# https://github.com/pandas-dev/pandas/issues/41485
645+
df = DataFrame([[1, 2, 3]], index=["a"])
646+
df2 = DataFrame([[4, 5, 6]], index=["b"])
647+
648+
msg = (
649+
"In a future version of pandas all arguments of concat "
650+
"except for the argument 'objs' will be keyword-only"
651+
)
652+
with tm.assert_produces_warning(FutureWarning, match=msg):
653+
result = concat([df, df2], 0)
654+
expected = DataFrame([[1, 2, 3], [4, 5, 6]], index=["a", "b"])
655+
tm.assert_frame_equal(result, expected)

pandas/tests/reshape/concat/test_invalid.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ def test_concat_invalid(self):
2727

2828
def test_concat_invalid_first_argument(self):
2929
df1 = tm.makeCustomDataframe(10, 2)
30-
df2 = tm.makeCustomDataframe(10, 2)
3130
msg = (
3231
"first argument must be an iterable of pandas "
3332
'objects, you passed an object of type "DataFrame"'
3433
)
3534
with pytest.raises(TypeError, match=msg):
36-
concat(df1, df2)
35+
concat(df1)
3736

3837
# generator ok though
3938
concat(DataFrame(np.random.rand(5, 5)) for _ in range(3))

0 commit comments

Comments
 (0)