Skip to content

TST: 2d index when constructing dataframe (#25416). #29083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down