Skip to content

Commit cc9ae26

Browse files
committed
perf?
1 parent fd56bb1 commit cc9ae26

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pandas/core/strings.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,12 +2139,15 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
21392139
# if join is None, _get_series_list already aligned indexes
21402140
join = 'left' if join is None else join
21412141

2142-
# Need to add keys for uniqueness in case of duplicate columns
2143-
others = concat(others, axis=1,
2144-
join=(join if join == 'inner' else 'outer'),
2145-
keys=range(len(others)))
2146-
data, others = data.align(others, join=join)
2147-
df = concat([data, others], axis=1).astype('object')
2142+
if any(not data.index.equals(x.index) for x in others):
2143+
# Need to add keys for uniqueness in case of duplicate columns
2144+
others = concat(others, axis=1,
2145+
join=(join if join == 'inner' else 'outer'),
2146+
keys=range(len(others)), copy=False)
2147+
data, others = data.align(others, join=join)
2148+
df = concat([data, others], axis=1, copy=False).astype('object')
2149+
else:
2150+
df = concat([data] + others, axis=1, copy=False).astype('object')
21482151

21492152
# calculate in numpy using str_cat_core; result is 1-dim np.ndarray
21502153
if na_rep is None:

0 commit comments

Comments
 (0)