Skip to content

Commit af59c41

Browse files
committed
BUG: assign consensus name to index union in array case GH13475
1 parent 3b1d4f1 commit af59c41

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

pandas/core/indexes/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,8 @@ def conv(i):
218218
return result
219219
elif kind == "array":
220220
index = indexes[0]
221-
for other in indexes[1:]:
222-
if not index.equals(other):
223-
return _unique_indices(indexes)
221+
if not all(index.equals(other) for other in indexes[1:]):
222+
index = _unique_indices(indexes)
224223

225224
name = get_consensus_names(indexes)[0]
226225
if name != index.name:

pandas/tests/reshape/test_concat.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,33 @@ def test_concat_ignore_index(self, sort):
12791279

12801280
tm.assert_frame_equal(v1, expected)
12811281

1282+
@pytest.mark.parametrize(
1283+
"input_names,output_name",
1284+
[
1285+
(["idx", "idx"], "idx"),
1286+
(["idx", None], "idx"),
1287+
([None, None], None),
1288+
(["idx1", "idx2"], None),
1289+
(["idx", "idx", None], "idx"),
1290+
(["idx1", "idx2", None], None),
1291+
],
1292+
)
1293+
def test_concat_same_index_names(self, input_names, output_name):
1294+
# GH13475
1295+
indices = [pd.Index(["a", "b", "c"], name=n) for n in input_names]
1296+
frames = [
1297+
pd.DataFrame({c: [0, 1, 2]}, index=i)
1298+
for i, c in zip(indices, ["x", "y", "z"])
1299+
]
1300+
result = pd.concat(frames, axis=1)
1301+
1302+
exp_ind = pd.Index(["a", "b", "c"], name=output_name)
1303+
expected = pd.DataFrame(
1304+
{c: [0, 1, 2] for _, c in zip(input_names, ["x", "y", "z"])}, index=exp_ind
1305+
)
1306+
1307+
tm.assert_frame_equal(result, expected)
1308+
12821309
def test_concat_multiindex_with_keys(self):
12831310
index = MultiIndex(
12841311
levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],

0 commit comments

Comments
 (0)