@@ -1938,6 +1938,30 @@ def test_rsplit_to_multiindex_expand(self):
19381938 tm .assert_index_equal (result , exp )
19391939 self .assertEqual (result .nlevels , 2 )
19401940
1941+ def test_split_with_name (self ):
1942+ # GH 12617
1943+
1944+ # should preserve name
1945+ s = Series (['a,b' , 'c,d' ], name = 'xxx' )
1946+ res = s .str .split (',' )
1947+ exp = Series ([('a' , 'b' ), ('c' , 'd' )], name = 'xxx' )
1948+ tm .assert_series_equal (res , exp )
1949+
1950+ res = s .str .split (',' , expand = True )
1951+ exp = DataFrame ([['a' , 'b' ], ['c' , 'd' ]])
1952+ tm .assert_frame_equal (res , exp )
1953+
1954+ idx = Index (['a,b' , 'c,d' ], name = 'xxx' )
1955+ res = idx .str .split (',' )
1956+ exp = Index ([['a' , 'b' ], ['c' , 'd' ]], name = 'xxx' )
1957+ self .assertTrue (res .nlevels , 1 )
1958+ tm .assert_index_equal (res , exp )
1959+
1960+ res = idx .str .split (',' , expand = True )
1961+ exp = MultiIndex .from_tuples ([('a' , 'b' ), ('c' , 'd' )])
1962+ self .assertTrue (res .nlevels , 2 )
1963+ tm .assert_index_equal (res , exp )
1964+
19411965 def test_partition_series (self ):
19421966 values = Series (['a_b_c' , 'c_d_e' , NA , 'f_g_h' ])
19431967
@@ -2059,6 +2083,31 @@ def test_partition_to_dataframe(self):
20592083 2 : ['c' , 'e' , np .nan , 'h' ]})
20602084 tm .assert_frame_equal (result , exp )
20612085
2086+ def test_partition_with_name (self ):
2087+ # GH 12617
2088+
2089+ s = Series (['a,b' , 'c,d' ], name = 'xxx' )
2090+ res = s .str .partition (',' )
2091+ exp = DataFrame ({0 : ['a' , 'c' ], 1 : [',' , ',' ], 2 : ['b' , 'd' ]})
2092+ tm .assert_frame_equal (res , exp )
2093+
2094+ # should preserve name
2095+ res = s .str .partition (',' , expand = False )
2096+ exp = Series ([('a' , ',' , 'b' ), ('c' , ',' , 'd' )], name = 'xxx' )
2097+ tm .assert_series_equal (res , exp )
2098+
2099+ idx = Index (['a,b' , 'c,d' ], name = 'xxx' )
2100+ res = idx .str .partition (',' )
2101+ exp = MultiIndex .from_tuples ([('a' , ',' , 'b' ), ('c' , ',' , 'd' )])
2102+ self .assertTrue (res .nlevels , 3 )
2103+ tm .assert_index_equal (res , exp )
2104+
2105+ # should preserve name
2106+ res = idx .str .partition (',' , expand = False )
2107+ exp = Index (np .array ([('a' , ',' , 'b' ), ('c' , ',' , 'd' )]), name = 'xxx' )
2108+ self .assertTrue (res .nlevels , 1 )
2109+ tm .assert_index_equal (res , exp )
2110+
20622111 def test_pipe_failures (self ):
20632112 # #2119
20642113 s = Series (['A|B|C' ])
0 commit comments