Skip to content

Commit 242690e

Browse files
committed
fix concat index name test to have partially-overlapping indices
1 parent af59c41 commit 242690e

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

pandas/tests/reshape/test_concat.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -1280,29 +1280,36 @@ def test_concat_ignore_index(self, sort):
12801280
tm.assert_frame_equal(v1, expected)
12811281

12821282
@pytest.mark.parametrize(
1283-
"input_names,output_name",
1283+
"name_in1,name_in2,name_in3,name_out",
12841284
[
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),
1285+
("idx", "idx", "idx", "idx"),
1286+
("idx", "idx", None, "idx"),
1287+
("idx", None, None, "idx"),
1288+
("idx1", "idx2", None, None),
1289+
("idx1", "idx1", "idx2", None),
1290+
("idx1", "idx2", "idx3", None),
1291+
(None, None, None, None),
12911292
],
12921293
)
1293-
def test_concat_same_index_names(self, input_names, output_name):
1294+
def test_concat_same_index_names(self, name_in1, name_in2, name_in3, name_out):
12941295
# GH13475
1295-
indices = [pd.Index(["a", "b", "c"], name=n) for n in input_names]
1296+
indices = [
1297+
pd.Index(["a", "b", "c"], name=name_in1),
1298+
pd.Index(["b", "c", "d"], name=name_in2),
1299+
pd.Index(["c", "d", "e"], name=name_in3),
1300+
]
12961301
frames = [
12971302
pd.DataFrame({c: [0, 1, 2]}, index=i)
12981303
for i, c in zip(indices, ["x", "y", "z"])
12991304
]
13001305
result = pd.concat(frames, axis=1)
13011306

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-
)
1307+
exp_ind = pd.Index(["a", "b", "c", "d", "e"], name=name_out)
1308+
expected = pd.DataFrame({
1309+
"x": [0, 1, 2, np.nan, np.nan],
1310+
"y": [np.nan, 0, 1, 2, np.nan],
1311+
"z": [np.nan, np.nan, 0, 1, 2],
1312+
}, index=exp_ind)
13061313

13071314
tm.assert_frame_equal(result, expected)
13081315

0 commit comments

Comments
 (0)