@@ -90,7 +90,7 @@ def _apply(self, f, dtype=None):
90
90
91
91
def len (self ):
92
92
"""
93
- Compute the length of each element in the array.
93
+ Compute the length of each string in the array.
94
94
95
95
Returns
96
96
-------
@@ -104,9 +104,9 @@ def __getitem__(self, key):
104
104
else :
105
105
return self .get (key )
106
106
107
- def get (self , i ):
107
+ def get (self , i , default = "" ):
108
108
"""
109
- Extract element from indexable in each element in the array.
109
+ Extract character number `i` from each string in the array.
110
110
111
111
Parameters
112
112
----------
@@ -120,12 +120,18 @@ def get(self, i):
120
120
-------
121
121
items : array of objects
122
122
"""
123
- obj = slice (- 1 , None ) if i == - 1 else slice (i , i + 1 )
124
- return self ._apply (lambda x : x [obj ])
123
+ s = slice (- 1 , None ) if i == - 1 else slice (i , i + 1 )
124
+
125
+ def f (x ):
126
+ item = x [s ]
127
+
128
+ return item if item else default
129
+
130
+ return self ._apply (f )
125
131
126
132
def slice (self , start = None , stop = None , step = None ):
127
133
"""
128
- Slice substrings from each element in the array.
134
+ Slice substrings from each string in the array.
129
135
130
136
Parameters
131
137
----------
@@ -359,7 +365,7 @@ def count(self, pat, flags=0):
359
365
360
366
def startswith (self , pat ):
361
367
"""
362
- Test if the start of each string element matches a pattern.
368
+ Test if the start of each string in the array matches a pattern.
363
369
364
370
Parameters
365
371
----------
@@ -378,7 +384,7 @@ def startswith(self, pat):
378
384
379
385
def endswith (self , pat ):
380
386
"""
381
- Test if the end of each string element matches a pattern.
387
+ Test if the end of each string in the array matches a pattern.
382
388
383
389
Parameters
384
390
----------
@@ -432,8 +438,7 @@ def pad(self, width, side="left", fillchar=" "):
432
438
433
439
def center (self , width , fillchar = " " ):
434
440
"""
435
- Filling left and right side of strings in the array with an
436
- additional character.
441
+ Pad left and right side of each string in the array.
437
442
438
443
Parameters
439
444
----------
@@ -451,8 +456,7 @@ def center(self, width, fillchar=" "):
451
456
452
457
def ljust (self , width , fillchar = " " ):
453
458
"""
454
- Filling right side of strings in the array with an additional
455
- character.
459
+ Pad right side of each string in the array.
456
460
457
461
Parameters
458
462
----------
@@ -470,7 +474,7 @@ def ljust(self, width, fillchar=" "):
470
474
471
475
def rjust (self , width , fillchar = " " ):
472
476
"""
473
- Filling left side of strings in the array with an additional character .
477
+ Pad left side of each string in the array.
474
478
475
479
Parameters
476
480
----------
@@ -488,7 +492,7 @@ def rjust(self, width, fillchar=" "):
488
492
489
493
def zfill (self , width ):
490
494
"""
491
- Pad strings in the array by prepending '0' characters.
495
+ Pad each string in the array by prepending '0' characters.
492
496
493
497
Strings in the array are padded with '0' characters on the
494
498
left of the string to reach a total string length `width`. Strings
@@ -508,7 +512,7 @@ def zfill(self, width):
508
512
509
513
def contains (self , pat , case = True , flags = 0 , regex = True ):
510
514
"""
511
- Test if pattern or regex is contained within a string of the array.
515
+ Test if pattern or regex is contained within each string of the array.
512
516
513
517
Return boolean array based on whether a given pattern or regex is
514
518
contained within a string of the array.
@@ -554,7 +558,7 @@ def contains(self, pat, case=True, flags=0, regex=True):
554
558
555
559
def match (self , pat , case = True , flags = 0 ):
556
560
"""
557
- Determine if each string matches a regular expression.
561
+ Determine if each string in the array matches a regular expression.
558
562
559
563
Parameters
560
564
----------
@@ -613,7 +617,7 @@ def strip(self, to_strip=None, side="both"):
613
617
614
618
def lstrip (self , to_strip = None ):
615
619
"""
616
- Remove leading and trailing characters.
620
+ Remove leading characters.
617
621
618
622
Strip whitespaces (including newlines) or a set of specified characters
619
623
from each string in the array from the left side.
@@ -633,7 +637,7 @@ def lstrip(self, to_strip=None):
633
637
634
638
def rstrip (self , to_strip = None ):
635
639
"""
636
- Remove leading and trailing characters.
640
+ Remove trailing characters.
637
641
638
642
Strip whitespaces (including newlines) or a set of specified characters
639
643
from each string in the array from the right side.
@@ -653,8 +657,7 @@ def rstrip(self, to_strip=None):
653
657
654
658
def wrap (self , width , ** kwargs ):
655
659
"""
656
- Wrap long strings in the array to be formatted in paragraphs with
657
- length less than a given width.
660
+ Wrap long strings in the array in paragraphs with length less than `width`.
658
661
659
662
This method has the same keyword parameters and defaults as
660
663
:class:`textwrap.TextWrapper`.
@@ -663,38 +666,20 @@ def wrap(self, width, **kwargs):
663
666
----------
664
667
width : int
665
668
Maximum line-width
666
- expand_tabs : bool, optional
667
- If true, tab characters will be expanded to spaces (default: True)
668
- replace_whitespace : bool, optional
669
- If true, each whitespace character (as defined by
670
- string.whitespace) remaining after tab expansion will be replaced
671
- by a single space (default: True)
672
- drop_whitespace : bool, optional
673
- If true, whitespace that, after wrapping, happens to end up at the
674
- beginning or end of a line is dropped (default: True)
675
- break_long_words : bool, optional
676
- If true, then words longer than width will be broken in order to
677
- ensure that no lines are longer than width. If it is false, long
678
- words will not be broken, and some lines may be longer than width.
679
- (default: True)
680
- break_on_hyphens : bool, optional
681
- If true, wrapping will occur preferably on whitespace and right
682
- after hyphens in compound words, as it is customary in English. If
683
- false, only whitespaces will be considered as potentially good
684
- places for line breaks, but you need to set break_long_words to
685
- false if you want truly insecable words. (default: True)
669
+ **kwargs
670
+ keyword arguments passed into :class:`textwrap.TextWrapper`.
686
671
687
672
Returns
688
673
-------
689
674
wrapped : same type as values
690
675
"""
691
- tw = textwrap .TextWrapper (width = width )
676
+ tw = textwrap .TextWrapper (width = width , ** kwargs )
692
677
f = lambda x : "\n " .join (tw .wrap (x ))
693
678
return self ._apply (f )
694
679
695
680
def translate (self , table ):
696
681
"""
697
- Map all characters in the string through the given mapping table.
682
+ Map characters of each string through the given mapping table.
698
683
699
684
Parameters
700
685
----------
0 commit comments