Skip to content

Commit 0ae6b27

Browse files
Backport PR #42541: REGR: concat(ints, bools) casting to object #42092 (#42548)
Co-authored-by: jbrockmendel <[email protected]>
1 parent c8d510e commit 0ae6b27

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v1.3.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Fixed regressions
2323
- Performance regression in :meth:`DataFrame.to_dict` and :meth:`Series.to_dict` when ``orient`` argument one of "records", "dict", or "split" (:issue:`42352`)
2424
- Fixed regression in indexing with a ``list`` subclass incorrectly raising ``TypeError`` (:issue:`42433`, :issue:`42461`)
2525
- Fixed regression in :meth:`DataFrame.isin` and :meth:`Series.isin` raising ``TypeError`` with nullable data containing at least one missing value (:issue:`42405`)
26-
-
26+
- Regression in :func:`concat` between objects with bool dtype and integer dtype casting to object instead of to integer (:issue:`42092`)
2727

2828
.. ---------------------------------------------------------------------------
2929

pandas/core/internals/concat.py

+3
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ def _is_uniform_join_units(join_units: list[JoinUnit]) -> bool:
592592
# e.g. DatetimeLikeBlock can be dt64 or td64, but these are not uniform
593593
all(
594594
is_dtype_equal(ju.block.dtype, join_units[0].block.dtype)
595+
# GH#42092 we only want the dtype_equal check for non-numeric blocks
596+
# (for now, may change but that would need a deprecation)
597+
or ju.block.dtype.kind in ["b", "i", "u"]
595598
for ju in join_units
596599
)
597600
and

pandas/tests/reshape/concat/test_dataframe.py

+10
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,13 @@ def test_concat_dataframe_keys_bug(self, sort):
170170
# it works
171171
result = concat([t1, t2], axis=1, keys=["t1", "t2"], sort=sort)
172172
assert list(result.columns) == [("t1", "value"), ("t2", "value")]
173+
174+
def test_concat_bool_with_int(self):
175+
# GH#42092 we may want to change this to return object, but that
176+
# would need a deprecation
177+
df1 = DataFrame(Series([True, False, True, True], dtype="bool"))
178+
df2 = DataFrame(Series([1, 0, 1], dtype="int64"))
179+
180+
result = concat([df1, df2])
181+
expected = concat([df1.astype("int64"), df2])
182+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)