From c2696ac3063cc84ba93d5a6e6554d5b6b5a90b81 Mon Sep 17 00:00:00 2001 From: jhereth Date: Sat, 19 Oct 2019 00:25:32 +0200 Subject: [PATCH] TST: 2d index when constructing dataframe (#25416). --- pandas/tests/frame/test_constructors.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index ebffeeaa3063e..583093af6d3e6 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -424,6 +424,25 @@ def test_constructor_multi_index(self): df = DataFrame(index=mi, columns=mi) assert pd.isna(df).values.ravel().all() + def test_constructor_2d_index(self): + # GH 25416 + # handling of 2d index in construction + df = pd.DataFrame([[1]], columns=[[1]], index=[1, 2]) + expected = pd.DataFrame( + [1, 1], + index=pd.Int64Index([1, 2], dtype="int64"), + columns=pd.MultiIndex(levels=[[1]], codes=[[0]]), + ) + tm.assert_frame_equal(df, expected) + + df = pd.DataFrame([[1]], columns=[[1]], index=[[1, 2]]) + expected = pd.DataFrame( + [1, 1], + index=pd.MultiIndex(levels=[[1, 2]], codes=[[0, 1]]), + columns=pd.MultiIndex(levels=[[1]], codes=[[0]]), + ) + tm.assert_frame_equal(df, expected) + def test_constructor_error_msgs(self): msg = "Empty data passed with indices specified." # passing an empty array with columns specified.