Skip to content
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

DEP: Deprecate non boolean sort for concat #44629

Merged
merged 2 commits into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ Other Deprecations
- Deprecated casting behavior when passing an item with mismatched-timezone to :meth:`DatetimeIndex.insert`, :meth:`DatetimeIndex.putmask`, :meth:`DatetimeIndex.where` :meth:`DatetimeIndex.fillna`, :meth:`Series.mask`, :meth:`Series.where`, :meth:`Series.fillna`, :meth:`Series.shift`, :meth:`Series.replace`, :meth:`Series.reindex` (and :class:`DataFrame` column analogues). In the past this has cast to object dtype. In a future version, these will cast the passed item to the index or series's timezone (:issue:`37605`)
- Deprecated the 'errors' keyword argument in :meth:`Series.where`, :meth:`DataFrame.where`, :meth:`Series.mask`, and meth:`DataFrame.mask`; in a future version the argument will be removed (:issue:`44294`)
- Deprecated :meth:`PeriodIndex.astype` to ``datetime64[ns]`` or ``DatetimeTZDtype``, use ``obj.to_timestamp(how).tz_localize(dtype.tz)`` instead (:issue:`44398`)
- Deprecated passing non boolean argument to sort in :func:`concat` (:issue:`41518`)
- Deprecated passing ``skipna=None`` for :meth:`DataFrame.mad` and :meth:`Series.mad`, pass ``skipna=True`` instead (:issue:`44580`)
- Deprecated :meth:`DateOffset.apply`, use ``offset + other`` instead (:issue:`44522`)
- A deprecation warning is now shown for :meth:`DataFrame.to_latex` indicating the arguments signature may change and emulate more the arguments to :meth:`.Styler.to_latex` in future versions (:issue:`44411`)
Expand Down
11 changes: 11 additions & 0 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
cast,
overload,
)
import warnings

import numpy as np

Expand All @@ -21,12 +22,14 @@
cache_readonly,
deprecate_nonkeyword_arguments,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.concat import concat_compat
from pandas.core.dtypes.generic import (
ABCDataFrame,
ABCSeries,
)
from pandas.core.dtypes.inference import is_bool
from pandas.core.dtypes.missing import isna

from pandas.core.arrays.categorical import (
Expand Down Expand Up @@ -519,6 +522,14 @@ def __init__(
self.keys = keys
self.names = names or getattr(keys, "names", None)
self.levels = levels

if not is_bool(sort):
warnings.warn(
jreback marked this conversation as resolved.
Show resolved Hide resolved
"Passing non boolean values for sort is deprecated and "
"will error in a future version!",
FutureWarning,
stacklevel=find_stack_level(),
)
self.sort = sort

self.ignore_index = ignore_index
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/reshape/concat/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_concat_empty_and_non_empty_series_regression(self):
result = concat([s1, s2])
tm.assert_series_equal(result, expected)

def test_concat_series_axis1(self, sort=sort):
def test_concat_series_axis1(self, sort):
ts = tm.makeTimeSeries()

pieces = [ts[:-2], ts[2:], ts[2:-2]]
Expand Down Expand Up @@ -79,7 +79,9 @@ def test_concat_series_axis1(self, sort=sort):
s = Series(np.random.randn(3), index=["c", "a", "b"], name="A")
s2 = Series(np.random.randn(4), index=["d", "a", "b", "c"], name="B")
result = concat([s, s2], axis=1, sort=sort)
expected = DataFrame({"A": s, "B": s2})
expected = DataFrame({"A": s, "B": s2}, index=["c", "a", "b", "d"])
if sort:
expected = expected.sort_index()
tm.assert_frame_equal(result, expected)

def test_concat_series_axis1_names_applied(self):
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/reshape/concat/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ def test_concat_frame_with_sort_false(self):
expected = DataFrame([[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1])

tm.assert_frame_equal(result, expected)

def test_concat_sort_none_warning(self):
# GH#41518
df = DataFrame({1: [1, 2], "a": [3, 4]})
with tm.assert_produces_warning(FutureWarning, match="sort"):
pd.concat([df, df], sort=None)