Skip to content

Commit 0d46203

Browse files
dsm054jreback
authored andcommitted
TST: Add test of building frame from named Series and columns (#9232) (#16700)
1 parent b7e7fd3 commit 0d46203

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/frame/test_constructors.py

+16
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,22 @@ def test_constructor_Series_named(self):
11081108
expected = DataFrame({1: s1, 0: arr}, columns=[0, 1])
11091109
tm.assert_frame_equal(df, expected)
11101110

1111+
def test_constructor_Series_named_and_columns(self):
1112+
# GH 9232 validation
1113+
1114+
s0 = Series(range(5), name=0)
1115+
s1 = Series(range(5), name=1)
1116+
1117+
# matching name and column gives standard frame
1118+
tm.assert_frame_equal(pd.DataFrame(s0, columns=[0]),
1119+
s0.to_frame())
1120+
tm.assert_frame_equal(pd.DataFrame(s1, columns=[1]),
1121+
s1.to_frame())
1122+
1123+
# non-matching produces empty frame
1124+
assert pd.DataFrame(s0, columns=[1]).empty
1125+
assert pd.DataFrame(s1, columns=[0]).empty
1126+
11111127
def test_constructor_Series_differently_indexed(self):
11121128
# name
11131129
s1 = Series([1, 2, 3], index=['a', 'b', 'c'], name='x')

0 commit comments

Comments
 (0)