@@ -1604,16 +1604,14 @@ def test_pad_fillchar(self):
16041604 result = values .str .pad (5 , fillchar = 5 )
16051605
16061606 def test_pad_width (self ):
1607-
16081607 values = Series (['1' , '22' , 'a' , 'bb' ])
1608+ string_methods = Series .str (values )
16091609
1610- result = values .str .pad (5 , side = 'left' , fillchar = '0' )
1611- expected = Series (['00001' , '00022' , '0000a' , '000bb' ])
1612- tm .assert_almost_equal (result , expected )
1613-
1614- with tm .assertRaisesRegexp (TypeError ,
1615- "width must be of integer type, not*" ):
1616- result = values .str .pad ('f' , fillchar = '0' )
1610+ for f_name , f in Series .str .__dict__ .items ():
1611+ if f_name in ['center' , 'ljust' , 'rjust' , 'zfill' , 'pad' ]:
1612+ with tm .assertRaisesRegexp (TypeError ,
1613+ "width must be of integer type,*" ):
1614+ f (string_methods , 'f' )
16171615
16181616 def test_translate (self ):
16191617
@@ -1757,33 +1755,6 @@ def test_center_ljust_rjust_fillchar(self):
17571755 "fillchar must be a character, not int" ):
17581756 result = values .str .rjust (5 , fillchar = 1 )
17591757
1760- def test_center_ljust_rjust_width (self ):
1761- values = Series (['a' , 'bb' , 'ccc' , NA , 'eeeee' ])
1762-
1763- result = values .str .center (4 , fillchar = 'X' )
1764- expected = Series (['XaXX' , 'XbbX' , 'cccX' , NA , 'eeeee' ])
1765- tm .assert_almost_equal (result , expected )
1766-
1767- result = values .str .ljust (4 , fillchar = 'X' )
1768- expected = Series (['aXXX' , 'bbXX' , 'cccX' , NA , 'eeeee' ])
1769- tm .assert_almost_equal (result , expected )
1770-
1771- result = values .str .rjust (4 , fillchar = 'X' )
1772- expected = Series (['XXXa' , 'XXbb' , 'Xccc' , NA , 'eeeee' ])
1773- tm .assert_almost_equal (result , expected )
1774-
1775- with tm .assertRaisesRegexp (TypeError ,
1776- "width must be of integer type, not*" ):
1777- result = values .str .center ('f' , fillchar = 'X' )
1778-
1779- with tm .assertRaisesRegexp (TypeError ,
1780- "width must be of integer type, not*" ):
1781- result = values .str .ljust ('f' , fillchar = 'X' )
1782-
1783- with tm .assertRaisesRegexp (TypeError ,
1784- "width must be of integer type, not*" ):
1785- result = values .str .rjust ('f' , fillchar = 'X' )
1786-
17871758 def test_zfill (self ):
17881759 values = Series (['1' , '22' , 'aaa' , '333' , '45678' ])
17891760
@@ -1806,17 +1777,6 @@ def test_zfill(self):
18061777 expected = Series (['00001' , np .nan , '00aaa' , np .nan , '45678' ])
18071778 tm .assert_series_equal (result , expected )
18081779
1809- def test_zfill_width (self ):
1810- values = Series (['1' , '22' , 'ccc' , NA , 'eeeee' ])
1811-
1812- result = values .str .zfill (5 )
1813- expected = Series (['00001' , '00022' , '00ccc' , NA , 'eeeee' ])
1814- tm .assert_almost_equal (result , expected )
1815-
1816- with tm .assertRaisesRegexp (TypeError ,
1817- "width must be of integer type, not*" ):
1818- result = values .str .zfill ('f' )
1819-
18201780 def test_split (self ):
18211781 values = Series (['a_b_c' , 'c_d_e' , NA , 'f_g_h' ])
18221782
0 commit comments