@@ -628,6 +628,7 @@ def test_empty_str_methods(self):
628628 tm .assert_series_equal (empty_str , empty .str .center (42 ))
629629 tm .assert_series_equal (empty_list , empty .str .split ('a' ))
630630 tm .assert_series_equal (empty_str , empty .str .slice (stop = 1 ))
631+ tm .assert_series_equal (empty_str , empty .str .slice (step = 1 ))
631632 tm .assert_series_equal (empty_str , empty .str .strip ())
632633 tm .assert_series_equal (empty_str , empty .str .lstrip ())
633634 tm .assert_series_equal (empty_str , empty .str .rstrip ())
@@ -922,6 +923,17 @@ def test_slice(self):
922923 exp = Series (['foo' , 'bar' , NA , 'baz' ])
923924 tm .assert_series_equal (result , exp )
924925
926+ for start , stop , step in [(0 , 3 , - 1 ), (None , None , - 1 ),
927+ (3 , 10 , 2 ), (3 , 0 , - 1 )]:
928+ try :
929+ result = values .str .slice (start , stop , step )
930+ expected = Series ([s [start :stop :step ] if not isnull (s ) else NA for s in
931+ values ])
932+ tm .assert_series_equal (result , expected )
933+ except :
934+ print ('failed on %s:%s:%s' % (start , stop , step ))
935+ raise
936+
925937 # mixed
926938 mixed = Series (['aafootwo' , NA , 'aabartwo' , True , datetime .today (),
927939 None , 1 , 2. ])
@@ -933,6 +945,10 @@ def test_slice(self):
933945 tm .assert_isinstance (rs , Series )
934946 tm .assert_almost_equal (rs , xp )
935947
948+ rs = Series (mixed ).str .slice (2 , 5 , - 1 )
949+ xp = Series (['oof' , NA , 'rab' , NA , NA ,
950+ NA , NA , NA ])
951+
936952 # unicode
937953 values = Series ([u ('aafootwo' ), u ('aabartwo' ), NA ,
938954 u ('aabazqux' )])
@@ -941,6 +957,10 @@ def test_slice(self):
941957 exp = Series ([u ('foo' ), u ('bar' ), NA , u ('baz' )])
942958 tm .assert_series_equal (result , exp )
943959
960+ result = values .str .slice (0 , - 1 , 2 )
961+ exp = Series ([u ('afow' ), u ('abrw' ), NA , u ('abzu' )])
962+ tm .assert_series_equal (result , exp )
963+
944964 def test_slice_replace (self ):
945965 pass
946966
@@ -1151,6 +1171,10 @@ def test_string_slice_get_syntax(self):
11511171 expected = s .str .slice (stop = 3 )
11521172 assert_series_equal (result , expected )
11531173
1174+ result = s .str [2 ::- 1 ]
1175+ expected = s .str .slice (start = 2 , step = - 1 )
1176+ assert_series_equal (result , expected )
1177+
11541178 def test_string_slice_out_of_bounds (self ):
11551179 s = Series ([(1 , 2 ), (1 ,), (3 ,4 ,5 )])
11561180
0 commit comments