@@ -628,6 +628,7 @@ def test_empty_str_methods(self):
628
628
tm .assert_series_equal (empty_str , empty .str .center (42 ))
629
629
tm .assert_series_equal (empty_list , empty .str .split ('a' ))
630
630
tm .assert_series_equal (empty_str , empty .str .slice (stop = 1 ))
631
+ tm .assert_series_equal (empty_str , empty .str .slice (step = 1 ))
631
632
tm .assert_series_equal (empty_str , empty .str .strip ())
632
633
tm .assert_series_equal (empty_str , empty .str .lstrip ())
633
634
tm .assert_series_equal (empty_str , empty .str .rstrip ())
@@ -922,6 +923,17 @@ def test_slice(self):
922
923
exp = Series (['foo' , 'bar' , NA , 'baz' ])
923
924
tm .assert_series_equal (result , exp )
924
925
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
+
925
937
# mixed
926
938
mixed = Series (['aafootwo' , NA , 'aabartwo' , True , datetime .today (),
927
939
None , 1 , 2. ])
@@ -933,6 +945,10 @@ def test_slice(self):
933
945
tm .assert_isinstance (rs , Series )
934
946
tm .assert_almost_equal (rs , xp )
935
947
948
+ rs = Series (mixed ).str .slice (2 , 5 , - 1 )
949
+ xp = Series (['oof' , NA , 'rab' , NA , NA ,
950
+ NA , NA , NA ])
951
+
936
952
# unicode
937
953
values = Series ([u ('aafootwo' ), u ('aabartwo' ), NA ,
938
954
u ('aabazqux' )])
@@ -941,6 +957,10 @@ def test_slice(self):
941
957
exp = Series ([u ('foo' ), u ('bar' ), NA , u ('baz' )])
942
958
tm .assert_series_equal (result , exp )
943
959
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
+
944
964
def test_slice_replace (self ):
945
965
pass
946
966
@@ -1151,6 +1171,10 @@ def test_string_slice_get_syntax(self):
1151
1171
expected = s .str .slice (stop = 3 )
1152
1172
assert_series_equal (result , expected )
1153
1173
1174
+ result = s .str [2 ::- 1 ]
1175
+ expected = s .str .slice (start = 2 , step = - 1 )
1176
+ assert_series_equal (result , expected )
1177
+
1154
1178
def test_string_slice_out_of_bounds (self ):
1155
1179
s = Series ([(1 , 2 ), (1 ,), (3 ,4 ,5 )])
1156
1180
0 commit comments