Skip to content

Commit 2a1660c

Browse files
committed
BUG: concat different EAs
1 parent 463c0bd commit 2a1660c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ update the ``ExtensionDtype._metadata`` tuple to match the signature of your
514514
- :meth:`Series.astype` and :meth:`DataFrame.astype` now dispatch to :meth:`ExtensionArray.astype` (:issue:`21185:`).
515515
- Slicing a single row of a ``DataFrame`` with multiple ExtensionArrays of the same type now preserves the dtype, rather than coercing to object (:issue:`22784`)
516516
- Added :meth:`pandas.api.types.register_extension_dtype` to register an extension type with pandas (:issue:`22664`)
517+
- Bug in concatenation an Series with two different extension dtypes not casting to object dtype (:issue:`22994`)
517518
- Updated the ``.type`` attribute for ``PeriodDtype``, ``DatetimeTZDtype``, and ``IntervalDtype`` to be instances of the dtype (``Period``, ``Timestamp``, and ``Interval`` respectively) (:issue:`22938`)
518519

519520
.. _whatsnew_0240.api.incompatibilities:

pandas/core/internals/managers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1634,8 +1634,7 @@ def concat(self, to_concat, new_axis):
16341634
# check if all series are of the same block type:
16351635
if len(non_empties) > 0:
16361636
blocks = [obj.blocks[0] for obj in non_empties]
1637-
1638-
if all(type(b) is type(blocks[0]) for b in blocks[1:]): # noqa
1637+
if len({b.dtype for b in blocks}) == 1:
16391638
new_block = blocks[0].concat_same_type(blocks)
16401639
else:
16411640
values = [x.values for x in blocks]

pandas/tests/reshape/test_concat.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from warnings import catch_warnings, simplefilter
22
from itertools import combinations
33
from collections import deque
4+
from decimal import Decimal
45

56
import datetime as dt
67
import dateutil
@@ -19,6 +20,7 @@
1920
from pandas.util import testing as tm
2021
from pandas.util.testing import (assert_frame_equal,
2122
makeCustomDataframe as mkdf)
23+
from pandas.tests.extension.decimal import to_decimal
2224

2325
import pytest
2426

@@ -2361,6 +2363,17 @@ def test_concat_datetime_timezone(self):
23612363
index=idx1.append(idx1))
23622364
tm.assert_frame_equal(result, expected)
23632365

2366+
def test_concat_different_extension_dtypes_upcasts(self):
2367+
a = pd.Series(pd.core.arrays.integer_array([1, 2]))
2368+
b = pd.Series(to_decimal([1, 2]))
2369+
2370+
result = pd.concat([a, b], ignore_index=True)
2371+
expected = pd.Series([
2372+
1, 2,
2373+
Decimal(1), Decimal(2)
2374+
], dtype=object)
2375+
tm.assert_series_equal(result, expected)
2376+
23642377

23652378
@pytest.mark.parametrize('pdt', [pd.Series, pd.DataFrame, pd.Panel])
23662379
@pytest.mark.parametrize('dt', np.sctypes['float'])

0 commit comments

Comments
 (0)