Skip to content

Commit 7fc30a0

Browse files
committed
rebase
1 parent 87a1d31 commit 7fc30a0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pandas/core/dtypes/concat.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _cast_to_common_type(arr: ArrayLike, dtype: DtypeObj) -> ArrayLike:
9898
return arr.astype(dtype, copy=False)
9999

100100

101-
def concat_compat(to_concat, axis: int = 0):
101+
def concat_compat(to_concat, axis: int = 0, ignore_2d_ea: bool = True):
102102
"""
103103
provide concatenation of an array of arrays each of which is a single
104104
'normalized' dtypes (in that for example, if it's object, then it is a
@@ -153,8 +153,13 @@ def is_nonempty(x) -> bool:
153153
return concat_datetime(to_concat, axis=axis, typs=typs)
154154

155155
elif any_ea and axis == 1:
156-
to_concat = [np.atleast_2d(x.astype("object")) for x in to_concat]
157-
return np.concatenate(to_concat, axis=axis)
156+
if single_dtype and ignore_2d_ea:
157+
# TODO(EA2D): special-casing not needed with 2D EAs
158+
cls = type(to_concat[0])
159+
return cls._concat_same_type(to_concat)
160+
else:
161+
to_concat = [np.atleast_2d(x.astype("object")) for x in to_concat]
162+
return np.concatenate(to_concat, axis=axis)
158163

159164
elif all_empty:
160165
# we have all empties, but may need to coerce the result dtype to

pandas/tests/extension/test_categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class TestConstructors(base.BaseConstructorsTests):
9494

9595
class TestReshaping(base.BaseReshapingTests):
9696
def test_concat_with_reindex(self, data):
97-
pytest.xfail(reason="Deliberate?")
97+
pytest.xfail(reason="Deliberately upcast to object?")
9898

9999

100100
class TestGetitem(base.BaseGetitemTests):

0 commit comments

Comments
 (0)