Skip to content

Commit 7d2337a

Browse files
authored
DEPR: enforce concat with bool dtype return object (#50077)
1 parent 1c71d7d commit 7d2337a

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ Removal of prior version deprecations/changes
562562
- Changed behavior of :meth:`SparseArray.astype` when given a dtype that is not explicitly ``SparseDtype``, cast to the exact requested dtype rather than silently using a ``SparseDtype`` instead (:issue:`34457`)
563563
- Changed behavior of :meth:`Index.ravel` to return a view on the original :class:`Index` instead of a ``np.ndarray`` (:issue:`36900`)
564564
- Changed behavior of :meth:`Series.to_frame` and :meth:`Index.to_frame` with explicit ``name=None`` to use ``None`` for the column name instead of the index's name or default ``0`` (:issue:`45523`)
565+
- Changed behavior of :func:`concat` with one array of ``bool``-dtype and another of integer dtype, this now returns ``object`` dtype instead of integer dtype; explicitly cast the bool object to integer before concatenating to get the old behavior (:issue:`45101`)
565566
- Changed behavior of :class:`DataFrame` constructor given floating-point ``data`` and an integer ``dtype``, when the data cannot be cast losslessly, the floating point dtype is retained, matching :class:`Series` behavior (:issue:`41170`)
566567
- Changed behavior of :class:`Index` constructor when given a ``np.ndarray`` with object-dtype containing numeric entries; this now retains object dtype rather than inferring a numeric dtype, consistent with :class:`Series` behavior (:issue:`42870`)
567568
- Changed behavior of :meth:`Index.__and__`, :meth:`Index.__or__` and :meth:`Index.__xor__` to behave as logical operations (matching :class:`Series` behavior) instead of aliases for set operations (:issue:`37374`)

pandas/core/dtypes/concat.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
from __future__ import annotations
55

66
from typing import TYPE_CHECKING
7-
import warnings
87

98
import numpy as np
109

1110
from pandas._typing import AxisInt
12-
from pandas.util._exceptions import find_stack_level
1311

1412
from pandas.core.dtypes.astype import astype_array
1513
from pandas.core.dtypes.cast import (
@@ -115,15 +113,8 @@ def is_nonempty(x) -> bool:
115113

116114
result = np.concatenate(to_concat, axis=axis)
117115
if "b" in kinds and result.dtype.kind in ["i", "u", "f"]:
118-
# GH#39817
119-
warnings.warn(
120-
"Behavior when concatenating bool-dtype and numeric-dtype arrays is "
121-
"deprecated; in a future version these will cast to object dtype "
122-
"(instead of coercing bools to numeric values). To retain the old "
123-
"behavior, explicitly cast bool-dtype arrays to numeric dtype.",
124-
FutureWarning,
125-
stacklevel=find_stack_level(),
126-
)
116+
# GH#39817 cast to object instead of casting bools to numeric
117+
result = result.astype(object, copy=False)
127118
return result
128119

129120

pandas/tests/reshape/concat/test_empty.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_concat_empty_series_timelike(self, tz, values):
9696
"left,right,expected",
9797
[
9898
# booleans
99-
(np.bool_, np.int32, np.int32),
99+
(np.bool_, np.int32, np.object_), # changed from int32 in 2.0 GH#39817
100100
(np.bool_, np.float32, np.object_),
101101
# datetime-like
102102
("m8[ns]", np.bool_, np.object_),
@@ -109,12 +109,8 @@ def test_concat_empty_series_timelike(self, tz, values):
109109
],
110110
)
111111
def test_concat_empty_series_dtypes(self, left, right, expected):
112-
warn = None
113-
if (left is np.bool_ or right is np.bool_) and expected is not np.object_:
114-
warn = FutureWarning
115-
with tm.assert_produces_warning(warn, match="concatenating bool-dtype"):
116-
# GH#39817
117-
result = concat([Series(dtype=left), Series(dtype=right)])
112+
# GH#39817, GH#45101
113+
result = concat([Series(dtype=left), Series(dtype=right)])
118114
assert result.dtype == expected
119115

120116
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)