Skip to content

Commit 845d164

Browse files
authored
DEP: Deprecate non boolean sort for concat (#44629)
1 parent c497b5f commit 845d164

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ Other Deprecations
468468
- 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`)
469469
- 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`)
470470
- Deprecated :meth:`PeriodIndex.astype` to ``datetime64[ns]`` or ``DatetimeTZDtype``, use ``obj.to_timestamp(how).tz_localize(dtype.tz)`` instead (:issue:`44398`)
471+
- Deprecated passing non boolean argument to sort in :func:`concat` (:issue:`41518`)
471472
- Deprecated passing ``skipna=None`` for :meth:`DataFrame.mad` and :meth:`Series.mad`, pass ``skipna=True`` instead (:issue:`44580`)
472473
- Deprecated :meth:`DateOffset.apply`, use ``offset + other`` instead (:issue:`44522`)
473474
- 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`)

pandas/core/reshape/concat.py

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
cast,
1414
overload,
1515
)
16+
import warnings
1617

1718
import numpy as np
1819

@@ -21,12 +22,14 @@
2122
cache_readonly,
2223
deprecate_nonkeyword_arguments,
2324
)
25+
from pandas.util._exceptions import find_stack_level
2426

2527
from pandas.core.dtypes.concat import concat_compat
2628
from pandas.core.dtypes.generic import (
2729
ABCDataFrame,
2830
ABCSeries,
2931
)
32+
from pandas.core.dtypes.inference import is_bool
3033
from pandas.core.dtypes.missing import isna
3134

3235
from pandas.core.arrays.categorical import (
@@ -519,6 +522,14 @@ def __init__(
519522
self.keys = keys
520523
self.names = names or getattr(keys, "names", None)
521524
self.levels = levels
525+
526+
if not is_bool(sort):
527+
warnings.warn(
528+
"Passing non boolean values for sort is deprecated and "
529+
"will error in a future version!",
530+
FutureWarning,
531+
stacklevel=find_stack_level(),
532+
)
522533
self.sort = sort
523534

524535
self.ignore_index = ignore_index

pandas/tests/reshape/concat/test_series.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_concat_empty_and_non_empty_series_regression(self):
5050
result = concat([s1, s2])
5151
tm.assert_series_equal(result, expected)
5252

53-
def test_concat_series_axis1(self, sort=sort):
53+
def test_concat_series_axis1(self, sort):
5454
ts = tm.makeTimeSeries()
5555

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

8587
def test_concat_series_axis1_names_applied(self):

pandas/tests/reshape/concat/test_sort.py

+6
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ def test_concat_frame_with_sort_false(self):
9292
expected = DataFrame([[2, np.nan], [np.nan, 1]], index=[2, 1], columns=[2, 1])
9393

9494
tm.assert_frame_equal(result, expected)
95+
96+
def test_concat_sort_none_warning(self):
97+
# GH#41518
98+
df = DataFrame({1: [1, 2], "a": [3, 4]})
99+
with tm.assert_produces_warning(FutureWarning, match="sort"):
100+
pd.concat([df, df], sort=None)

0 commit comments

Comments
 (0)