Skip to content

Commit 8929630

Browse files
authored
PERF: concat(axis=1) with unaligned indexes (#55084)
* PERF: concat(axis=1) with unaligned indexes * whatsnew
1 parent a0d4725 commit 8929630

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

doc/source/whatsnew/v2.2.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ Deprecations
158158

159159
Performance improvements
160160
~~~~~~~~~~~~~~~~~~~~~~~~
161+
- Performance improvement in :func:`concat` with ``axis=1`` and objects with unaligned indexes (:issue:`55084`)
161162
- Performance improvement in :func:`to_dict` on converting DataFrame to dictionary (:issue:`50990`)
162163
- Performance improvement in :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` when indexed by a :class:`MultiIndex` (:issue:`54835`)
163164
- Performance improvement when indexing with more than 4 keys (:issue:`54550`)
165+
-
164166

165167
.. ---------------------------------------------------------------------------
166168
.. _whatsnew_220.bug_fixes:

pandas/core/indexes/api.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,12 @@ def _unique_indices(inds, dtype) -> Index:
239239
Index
240240
"""
241241
if all(isinstance(ind, Index) for ind in inds):
242-
result = inds[0].append(inds[1:]).unique()
243-
result = result.astype(dtype, copy=False)
242+
inds = [ind.astype(dtype, copy=False) for ind in inds]
243+
result = inds[0].unique()
244+
other = inds[1].append(inds[2:])
245+
diff = other[result.get_indexer_for(other) == -1]
246+
if len(diff):
247+
result = result.append(diff.unique())
244248
if sort:
245249
result = result.sort_values()
246250
return result

0 commit comments

Comments
 (0)