Skip to content

Commit d5f430a

Browse files
jherethBlake Hawkins
authored and
Blake Hawkins
committed
TST: 2d index when constructing dataframe (pandas-dev#25416). (pandas-dev#29083)
1 parent 1f20f63 commit d5f430a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/frame/test_constructors.py

+19
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,25 @@ def test_constructor_multi_index(self):
424424
df = DataFrame(index=mi, columns=mi)
425425
assert pd.isna(df).values.ravel().all()
426426

427+
def test_constructor_2d_index(self):
428+
# GH 25416
429+
# handling of 2d index in construction
430+
df = pd.DataFrame([[1]], columns=[[1]], index=[1, 2])
431+
expected = pd.DataFrame(
432+
[1, 1],
433+
index=pd.Int64Index([1, 2], dtype="int64"),
434+
columns=pd.MultiIndex(levels=[[1]], codes=[[0]]),
435+
)
436+
tm.assert_frame_equal(df, expected)
437+
438+
df = pd.DataFrame([[1]], columns=[[1]], index=[[1, 2]])
439+
expected = pd.DataFrame(
440+
[1, 1],
441+
index=pd.MultiIndex(levels=[[1, 2]], codes=[[0, 1]]),
442+
columns=pd.MultiIndex(levels=[[1]], codes=[[0]]),
443+
)
444+
tm.assert_frame_equal(df, expected)
445+
427446
def test_constructor_error_msgs(self):
428447
msg = "Empty data passed with indices specified."
429448
# passing an empty array with columns specified.

0 commit comments

Comments
 (0)