Skip to content

Commit e67b8bf

Browse files
authored
REF: matching-dtype case first in concat_compat (#33530)
* remove _concat_datetimetz * Simplify concat_compat dispatch * revert non-central * Dummy commit to force CI
1 parent 50c2242 commit e67b8bf

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

pandas/core/dtypes/concat.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,15 @@ def is_nonempty(x) -> bool:
9595
_contains_datetime = any(typ.startswith("datetime") for typ in typs)
9696
_contains_period = any(typ.startswith("period") for typ in typs)
9797

98-
if "category" in typs:
98+
all_empty = not len(non_empties)
99+
single_dtype = len({x.dtype for x in to_concat}) == 1
100+
any_ea = any(is_extension_array_dtype(x.dtype) for x in to_concat)
101+
102+
if any_ea and single_dtype and axis == 0:
103+
cls = type(to_concat[0])
104+
return cls._concat_same_type(to_concat)
105+
106+
elif "category" in typs:
99107
# this must be prior to concat_datetime,
100108
# to support Categorical + datetime-like
101109
return concat_categorical(to_concat, axis=axis)
@@ -107,18 +115,11 @@ def is_nonempty(x) -> bool:
107115
elif "sparse" in typs:
108116
return _concat_sparse(to_concat, axis=axis, typs=typs)
109117

110-
all_empty = not len(non_empties)
111-
single_dtype = len({x.dtype for x in to_concat}) == 1
112-
any_ea = any(is_extension_array_dtype(x.dtype) for x in to_concat)
113-
114-
if any_ea and axis == 1:
118+
elif any_ea and axis == 1:
115119
to_concat = [np.atleast_2d(x.astype("object")) for x in to_concat]
120+
return np.concatenate(to_concat, axis=axis)
116121

117-
elif any_ea and single_dtype and axis == 0:
118-
cls = type(to_concat[0])
119-
return cls._concat_same_type(to_concat)
120-
121-
if all_empty:
122+
elif all_empty:
122123
# we have all empties, but may need to coerce the result dtype to
123124
# object if we have non-numeric type operands (numpy would otherwise
124125
# cast this to float)
@@ -282,15 +283,15 @@ def union_categoricals(
282283
[b, c, a, b]
283284
Categories (3, object): [b, c, a]
284285
"""
285-
from pandas import Index, Categorical
286+
from pandas import Categorical
286287
from pandas.core.arrays.categorical import recode_for_categories
287288

288289
if len(to_union) == 0:
289290
raise ValueError("No Categoricals to union")
290291

291292
def _maybe_unwrap(x):
292293
if isinstance(x, (ABCCategoricalIndex, ABCSeries)):
293-
return x.values
294+
return x._values
294295
elif isinstance(x, Categorical):
295296
return x
296297
else:
@@ -333,7 +334,7 @@ def _maybe_unwrap(x):
333334
elif ignore_order or all(not c.ordered for c in to_union):
334335
# different categories - union and recode
335336
cats = first.categories.append([c.categories for c in to_union[1:]])
336-
categories = Index(cats.unique())
337+
categories = cats.unique()
337338
if sort_categories:
338339
categories = categories.sort_values()
339340

0 commit comments

Comments
 (0)