Skip to content

DEPR: Deprecated passing arguments as positional in pd.concat #41718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/source/whatsnew/v0.17.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`)

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -84,6 +87,7 @@ def concat(
...


@deprecate_nonkeyword_arguments(version=None, allowed_args=["objs"])
def concat(
objs: Iterable[NDFrame] | Mapping[Hashable, NDFrame],
axis=0,
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/pytables/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions pandas/tests/reshape/concat/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 1 addition & 2 deletions pandas/tests/reshape/concat/test_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down