Skip to content

DEPR: enforce passing non boolean sort in concat #49472

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 1 commit into from
Nov 2, 2022
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/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Removal of prior version deprecations/changes
- Enforced deprecation disallowing unit-less "datetime64" dtype in :meth:`Series.astype` and :meth:`DataFrame.astype` (:issue:`47844`)
- Enforced deprecation disallowing using ``.astype`` to convert a ``datetime64[ns]`` :class:`Series`, :class:`DataFrame`, or :class:`DatetimeIndex` to timezone-aware dtype, use ``obj.tz_localize`` or ``ser.dt.tz_localize`` instead (:issue:`39258`)
- Enforced deprecation disallowing using ``.astype`` to convert a timezone-aware :class:`Series`, :class:`DataFrame`, or :class:`DatetimeIndex` to timezone-naive ``datetime64[ns]`` dtype, use ``obj.tz_localize(None)`` or ``obj.tz_convert("UTC").tz_localize(None)`` instead (:issue:`39258`)
- Enforced deprecation disallowing passing non boolean argument to sort in :func:`concat` (:issue:`44629`)
- Removed Date parser functions :func:`~pandas.io.date_converters.parse_date_time`,
:func:`~pandas.io.date_converters.parse_date_fields`, :func:`~pandas.io.date_converters.parse_all_fields`
and :func:`~pandas.io.date_converters.generic_parser` (:issue:`24518`)
Expand Down
9 changes: 2 additions & 7 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
cast,
overload,
)
import warnings

import numpy as np

Expand All @@ -24,7 +23,6 @@
HashableT,
)
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.concat import concat_compat
from pandas.core.dtypes.generic import (
Expand Down Expand Up @@ -551,11 +549,8 @@ def __init__(
self.levels = levels

if not is_bool(sort):
warnings.warn(
"Passing non boolean values for sort is deprecated and "
"will error in a future version!",
FutureWarning,
stacklevel=find_stack_level(),
raise ValueError(
f"The 'sort' keyword only accepts boolean values; {sort} was passed."
)
self.sort = sort

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/reshape/concat/test_sort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

import pandas as pd
from pandas import DataFrame
Expand Down Expand Up @@ -109,8 +110,9 @@ def test_concat_frame_with_sort_false(self):
)
tm.assert_frame_equal(result, expected)

def test_concat_sort_none_warning(self):
def test_concat_sort_none_raises(self):
# GH#41518
df = DataFrame({1: [1, 2], "a": [3, 4]})
with tm.assert_produces_warning(FutureWarning, match="sort"):
msg = "The 'sort' keyword only accepts boolean values; None was passed."
with pytest.raises(ValueError, match=msg):
pd.concat([df, df], sort=None)