@@ -506,7 +506,7 @@ def str_split(arr, pat, n=0):
506
506
return _na_map (f , arr )
507
507
508
508
509
- def str_slice (arr , start = None , stop = None ):
509
+ def str_slice (arr , start = None , stop = None , step = 1 ):
510
510
"""
511
511
Slice substrings from each element in array
512
512
@@ -519,7 +519,7 @@ def str_slice(arr, start=None, stop=None):
519
519
-------
520
520
sliced : array
521
521
"""
522
- obj = slice (start , stop )
522
+ obj = slice (start , stop , step )
523
523
f = lambda x : x [obj ]
524
524
return _na_map (f , arr )
525
525
@@ -649,6 +649,13 @@ class StringMethods(object):
649
649
def __init__ (self , series ):
650
650
self .series = series
651
651
652
+ def __getitem__ (self , key ):
653
+ if isinstance (key , slice ):
654
+ return self .slice (start = key .start , stop = key .stop ,
655
+ step = key .step )
656
+ else :
657
+ return self .get (key )
658
+
652
659
def _wrap_result (self , result ):
653
660
return Series (result , index = self .series .index ,
654
661
name = self .series .name )
@@ -699,7 +706,7 @@ def center(self, width):
699
706
return self ._wrap_result (result )
700
707
701
708
@copy (str_slice )
702
- def slice (self , start = None , stop = None ):
709
+ def slice (self , start = None , stop = None , step = 1 ):
703
710
result = str_slice (self .series , start , stop )
704
711
return self ._wrap_result (result )
705
712
0 commit comments