@@ -104,7 +104,7 @@ def wrapper(self, *args, **kwargs):
104
104
def _map_and_wrap (name , docstring ):
105
105
@forbid_nonstring_types (["bytes" ], name = name )
106
106
def wrapper (self ):
107
- result = getattr (self ._array , f"_str_{ name } " )()
107
+ result = getattr (self ._data . array , f"_str_{ name } " )()
108
108
return self ._wrap_result (result )
109
109
110
110
wrapper .__doc__ = docstring
@@ -149,8 +149,7 @@ def __init__(self, data):
149
149
self ._inferred_dtype = self ._validate (data )
150
150
self ._is_categorical = is_categorical_dtype (data .dtype )
151
151
self ._is_string = isinstance (data .dtype , StringDtype )
152
- array = data .array
153
- self ._array = array
152
+ self ._data = data
154
153
155
154
self ._index = self ._name = None
156
155
if isinstance (data , ABCSeries ):
@@ -214,7 +213,7 @@ def _validate(data):
214
213
return inferred_dtype
215
214
216
215
def __getitem__ (self , key ):
217
- result = self ._array ._str_getitem (key )
216
+ result = self ._data . array ._str_getitem (key )
218
217
return self ._wrap_result (result )
219
218
220
219
def __iter__ (self ):
@@ -739,13 +738,13 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
739
738
@Appender (_shared_docs ["str_split" ] % {"side" : "beginning" , "method" : "split" })
740
739
@forbid_nonstring_types (["bytes" ])
741
740
def split (self , pat = None , n = - 1 , expand = False ):
742
- result = self ._array ._str_split (pat , n , expand )
741
+ result = self ._data . array ._str_split (pat , n , expand )
743
742
return self ._wrap_result (result , returns_string = expand , expand = expand )
744
743
745
744
@Appender (_shared_docs ["str_split" ] % {"side" : "end" , "method" : "rsplit" })
746
745
@forbid_nonstring_types (["bytes" ])
747
746
def rsplit (self , pat = None , n = - 1 , expand = False ):
748
- result = self ._array ._str_rsplit (pat , n = n )
747
+ result = self ._data . array ._str_rsplit (pat , n = n )
749
748
return self ._wrap_result (result , expand = expand , returns_string = expand )
750
749
751
750
_shared_docs [
@@ -841,7 +840,7 @@ def rsplit(self, pat=None, n=-1, expand=False):
841
840
)
842
841
@forbid_nonstring_types (["bytes" ])
843
842
def partition (self , sep = " " , expand = True ):
844
- result = self ._array ._str_partition (sep , expand )
843
+ result = self ._data . array ._str_partition (sep , expand )
845
844
return self ._wrap_result (result , expand = expand , returns_string = expand )
846
845
847
846
@Appender (
@@ -855,7 +854,7 @@ def partition(self, sep=" ", expand=True):
855
854
)
856
855
@forbid_nonstring_types (["bytes" ])
857
856
def rpartition (self , sep = " " , expand = True ):
858
- result = self ._array ._str_rpartition (sep , expand )
857
+ result = self ._data . array ._str_rpartition (sep , expand )
859
858
return self ._wrap_result (result , expand = expand , returns_string = expand )
860
859
861
860
def get (self , i ):
@@ -909,7 +908,7 @@ def get(self, i):
909
908
5 None
910
909
dtype: object
911
910
"""
912
- result = self ._array ._str_get (i )
911
+ result = self ._data . array ._str_get (i )
913
912
return self ._wrap_result (result )
914
913
915
914
@forbid_nonstring_types (["bytes" ])
@@ -975,7 +974,7 @@ def join(self, sep):
975
974
4 NaN
976
975
dtype: object
977
976
"""
978
- result = self ._array ._str_join (sep )
977
+ result = self ._data . array ._str_join (sep )
979
978
return self ._wrap_result (result )
980
979
981
980
@forbid_nonstring_types (["bytes" ])
@@ -1103,7 +1102,7 @@ def contains(self, pat, case=True, flags=0, na=None, regex=True):
1103
1102
4 False
1104
1103
dtype: bool
1105
1104
"""
1106
- result = self ._array ._str_contains (pat , case , flags , na , regex )
1105
+ result = self ._data . array ._str_contains (pat , case , flags , na , regex )
1107
1106
return self ._wrap_result (result , fill_value = na , returns_string = False )
1108
1107
1109
1108
@forbid_nonstring_types (["bytes" ])
@@ -1135,7 +1134,7 @@ def match(self, pat, case=True, flags=0, na=None):
1135
1134
re.match.
1136
1135
extract : Extract matched groups.
1137
1136
"""
1138
- result = self ._array ._str_match (pat , case = case , flags = flags , na = na )
1137
+ result = self ._data . array ._str_match (pat , case = case , flags = flags , na = na )
1139
1138
return self ._wrap_result (result , fill_value = na , returns_string = False )
1140
1139
1141
1140
@forbid_nonstring_types (["bytes" ])
@@ -1168,7 +1167,7 @@ def fullmatch(self, pat, case=True, flags=0, na=None):
1168
1167
matches the regular expression.
1169
1168
extract : Extract matched groups.
1170
1169
"""
1171
- result = self ._array ._str_fullmatch (pat , case = case , flags = flags , na = na )
1170
+ result = self ._data . array ._str_fullmatch (pat , case = case , flags = flags , na = na )
1172
1171
return self ._wrap_result (result , fill_value = na , returns_string = False )
1173
1172
1174
1173
@forbid_nonstring_types (["bytes" ])
@@ -1304,7 +1303,7 @@ def replace(self, pat, repl, n=-1, case=None, flags=0, regex=None):
1304
1303
)
1305
1304
warnings .warn (msg , FutureWarning , stacklevel = 3 )
1306
1305
regex = True
1307
- result = self ._array ._str_replace (
1306
+ result = self ._data . array ._str_replace (
1308
1307
pat , repl , n = n , case = case , flags = flags , regex = regex
1309
1308
)
1310
1309
return self ._wrap_result (result )
@@ -1350,7 +1349,7 @@ def repeat(self, repeats):
1350
1349
2 ccc
1351
1350
dtype: object
1352
1351
"""
1353
- result = self ._array ._str_repeat (repeats )
1352
+ result = self ._data . array ._str_repeat (repeats )
1354
1353
return self ._wrap_result (result )
1355
1354
1356
1355
@forbid_nonstring_types (["bytes" ])
@@ -1418,7 +1417,7 @@ def pad(self, width, side="left", fillchar=" "):
1418
1417
msg = f"width must be of integer type, not { type (width ).__name__ } "
1419
1418
raise TypeError (msg )
1420
1419
1421
- result = self ._array ._str_pad (width , side = side , fillchar = fillchar )
1420
+ result = self ._data . array ._str_pad (width , side = side , fillchar = fillchar )
1422
1421
return self ._wrap_result (result )
1423
1422
1424
1423
_shared_docs [
@@ -1592,7 +1591,7 @@ def slice(self, start=None, stop=None, step=None):
1592
1591
2 cm
1593
1592
dtype: object
1594
1593
"""
1595
- result = self ._array ._str_slice (start , stop , step )
1594
+ result = self ._data . array ._str_slice (start , stop , step )
1596
1595
return self ._wrap_result (result )
1597
1596
1598
1597
@forbid_nonstring_types (["bytes" ])
@@ -1668,7 +1667,7 @@ def slice_replace(self, start=None, stop=None, repl=None):
1668
1667
4 aXde
1669
1668
dtype: object
1670
1669
"""
1671
- result = self ._array ._str_slice_replace (start , stop , repl )
1670
+ result = self ._data . array ._str_slice_replace (start , stop , repl )
1672
1671
return self ._wrap_result (result )
1673
1672
1674
1673
def decode (self , encoding , errors = "strict" ):
@@ -1694,7 +1693,7 @@ def decode(self, encoding, errors="strict"):
1694
1693
else :
1695
1694
decoder = codecs .getdecoder (encoding )
1696
1695
f = lambda x : decoder (x , errors )[0 ]
1697
- arr = self ._array
1696
+ arr = self ._data . array
1698
1697
# assert isinstance(arr, (StringArray,))
1699
1698
result = arr ._str_map (f )
1700
1699
return self ._wrap_result (result )
@@ -1715,7 +1714,7 @@ def encode(self, encoding, errors="strict"):
1715
1714
-------
1716
1715
encoded : Series/Index of objects
1717
1716
"""
1718
- result = self ._array ._str_encode (encoding , errors )
1717
+ result = self ._data . array ._str_encode (encoding , errors )
1719
1718
return self ._wrap_result (result , returns_string = False )
1720
1719
1721
1720
_shared_docs [
@@ -1793,7 +1792,7 @@ def encode(self, encoding, errors="strict"):
1793
1792
)
1794
1793
@forbid_nonstring_types (["bytes" ])
1795
1794
def strip (self , to_strip = None ):
1796
- result = self ._array ._str_strip (to_strip )
1795
+ result = self ._data . array ._str_strip (to_strip )
1797
1796
return self ._wrap_result (result )
1798
1797
1799
1798
@Appender (
@@ -1802,7 +1801,7 @@ def strip(self, to_strip=None):
1802
1801
)
1803
1802
@forbid_nonstring_types (["bytes" ])
1804
1803
def lstrip (self , to_strip = None ):
1805
- result = self ._array ._str_lstrip (to_strip )
1804
+ result = self ._data . array ._str_lstrip (to_strip )
1806
1805
return self ._wrap_result (result )
1807
1806
1808
1807
@Appender (
@@ -1811,7 +1810,7 @@ def lstrip(self, to_strip=None):
1811
1810
)
1812
1811
@forbid_nonstring_types (["bytes" ])
1813
1812
def rstrip (self , to_strip = None ):
1814
- result = self ._array ._str_rstrip (to_strip )
1813
+ result = self ._data . array ._str_rstrip (to_strip )
1815
1814
return self ._wrap_result (result )
1816
1815
1817
1816
@forbid_nonstring_types (["bytes" ])
@@ -1870,7 +1869,7 @@ def wrap(self, width, **kwargs):
1870
1869
1 another line\nto be\nwrapped
1871
1870
dtype: object
1872
1871
"""
1873
- result = self ._array ._str_wrap (width , ** kwargs )
1872
+ result = self ._data . array ._str_wrap (width , ** kwargs )
1874
1873
return self ._wrap_result (result )
1875
1874
1876
1875
@forbid_nonstring_types (["bytes" ])
@@ -1912,7 +1911,7 @@ def get_dummies(self, sep="|"):
1912
1911
"""
1913
1912
# we need to cast to Series of strings as only that has all
1914
1913
# methods available for making the dummies...
1915
- result , name = self ._array ._str_get_dummies (sep )
1914
+ result , name = self ._data . array ._str_get_dummies (sep )
1916
1915
return self ._wrap_result (
1917
1916
result ,
1918
1917
name = name ,
@@ -1939,7 +1938,7 @@ def translate(self, table):
1939
1938
-------
1940
1939
Series or Index
1941
1940
"""
1942
- result = self ._array ._str_translate (table )
1941
+ result = self ._data . array ._str_translate (table )
1943
1942
return self ._wrap_result (result )
1944
1943
1945
1944
@forbid_nonstring_types (["bytes" ])
@@ -2007,7 +2006,7 @@ def count(self, pat, flags=0):
2007
2006
>>> pd.Index(['A', 'A', 'Aaba', 'cat']).str.count('a')
2008
2007
Int64Index([0, 0, 2, 1], dtype='int64')
2009
2008
"""
2010
- result = self ._array ._str_count (pat , flags )
2009
+ result = self ._data . array ._str_count (pat , flags )
2011
2010
return self ._wrap_result (result , returns_string = False )
2012
2011
2013
2012
@forbid_nonstring_types (["bytes" ])
@@ -2064,7 +2063,7 @@ def startswith(self, pat, na=None):
2064
2063
3 False
2065
2064
dtype: bool
2066
2065
"""
2067
- result = self ._array ._str_startswith (pat , na = na )
2066
+ result = self ._data . array ._str_startswith (pat , na = na )
2068
2067
return self ._wrap_result (result , returns_string = False )
2069
2068
2070
2069
@forbid_nonstring_types (["bytes" ])
@@ -2121,7 +2120,7 @@ def endswith(self, pat, na=None):
2121
2120
3 False
2122
2121
dtype: bool
2123
2122
"""
2124
- result = self ._array ._str_endswith (pat , na = na )
2123
+ result = self ._data . array ._str_endswith (pat , na = na )
2125
2124
return self ._wrap_result (result , returns_string = False )
2126
2125
2127
2126
@forbid_nonstring_types (["bytes" ])
@@ -2214,7 +2213,7 @@ def findall(self, pat, flags=0):
2214
2213
2 [b, b]
2215
2214
dtype: object
2216
2215
"""
2217
- result = self ._array ._str_findall (pat , flags )
2216
+ result = self ._data . array ._str_findall (pat , flags )
2218
2217
return self ._wrap_result (result , returns_string = False )
2219
2218
2220
2219
@forbid_nonstring_types (["bytes" ])
@@ -2421,7 +2420,7 @@ def find(self, sub, start=0, end=None):
2421
2420
msg = f"expected a string object, not { type (sub ).__name__ } "
2422
2421
raise TypeError (msg )
2423
2422
2424
- result = self ._array ._str_find (sub , start , end )
2423
+ result = self ._data . array ._str_find (sub , start , end )
2425
2424
return self ._wrap_result (result , returns_string = False )
2426
2425
2427
2426
@Appender (
@@ -2438,7 +2437,7 @@ def rfind(self, sub, start=0, end=None):
2438
2437
msg = f"expected a string object, not { type (sub ).__name__ } "
2439
2438
raise TypeError (msg )
2440
2439
2441
- result = self ._array ._str_rfind (sub , start = start , end = end )
2440
+ result = self ._data . array ._str_rfind (sub , start = start , end = end )
2442
2441
return self ._wrap_result (result , returns_string = False )
2443
2442
2444
2443
@forbid_nonstring_types (["bytes" ])
@@ -2458,7 +2457,7 @@ def normalize(self, form):
2458
2457
-------
2459
2458
normalized : Series/Index of objects
2460
2459
"""
2461
- result = self ._array ._str_normalize (form )
2460
+ result = self ._data . array ._str_normalize (form )
2462
2461
return self ._wrap_result (result )
2463
2462
2464
2463
_shared_docs [
@@ -2505,7 +2504,7 @@ def index(self, sub, start=0, end=None):
2505
2504
msg = f"expected a string object, not { type (sub ).__name__ } "
2506
2505
raise TypeError (msg )
2507
2506
2508
- result = self ._array ._str_index (sub , start = start , end = end )
2507
+ result = self ._data . array ._str_index (sub , start = start , end = end )
2509
2508
return self ._wrap_result (result , returns_string = False )
2510
2509
2511
2510
@Appender (
@@ -2523,7 +2522,7 @@ def rindex(self, sub, start=0, end=None):
2523
2522
msg = f"expected a string object, not { type (sub ).__name__ } "
2524
2523
raise TypeError (msg )
2525
2524
2526
- result = self ._array ._str_rindex (sub , start = start , end = end )
2525
+ result = self ._data . array ._str_rindex (sub , start = start , end = end )
2527
2526
return self ._wrap_result (result , returns_string = False )
2528
2527
2529
2528
def len (self ):
@@ -2572,7 +2571,7 @@ def len(self):
2572
2571
5 3.0
2573
2572
dtype: float64
2574
2573
"""
2575
- result = self ._array ._str_len ()
2574
+ result = self ._data . array ._str_len ()
2576
2575
return self ._wrap_result (result , returns_string = False )
2577
2576
2578
2577
_shared_docs [
@@ -2672,37 +2671,37 @@ def len(self):
2672
2671
@Appender (_shared_docs ["casemethods" ] % _doc_args ["lower" ])
2673
2672
@forbid_nonstring_types (["bytes" ])
2674
2673
def lower (self ):
2675
- result = self ._array ._str_lower ()
2674
+ result = self ._data . array ._str_lower ()
2676
2675
return self ._wrap_result (result )
2677
2676
2678
2677
@Appender (_shared_docs ["casemethods" ] % _doc_args ["upper" ])
2679
2678
@forbid_nonstring_types (["bytes" ])
2680
2679
def upper (self ):
2681
- result = self ._array ._str_upper ()
2680
+ result = self ._data . array ._str_upper ()
2682
2681
return self ._wrap_result (result )
2683
2682
2684
2683
@Appender (_shared_docs ["casemethods" ] % _doc_args ["title" ])
2685
2684
@forbid_nonstring_types (["bytes" ])
2686
2685
def title (self ):
2687
- result = self ._array ._str_title ()
2686
+ result = self ._data . array ._str_title ()
2688
2687
return self ._wrap_result (result )
2689
2688
2690
2689
@Appender (_shared_docs ["casemethods" ] % _doc_args ["capitalize" ])
2691
2690
@forbid_nonstring_types (["bytes" ])
2692
2691
def capitalize (self ):
2693
- result = self ._array ._str_capitalize ()
2692
+ result = self ._data . array ._str_capitalize ()
2694
2693
return self ._wrap_result (result )
2695
2694
2696
2695
@Appender (_shared_docs ["casemethods" ] % _doc_args ["swapcase" ])
2697
2696
@forbid_nonstring_types (["bytes" ])
2698
2697
def swapcase (self ):
2699
- result = self ._array ._str_swapcase ()
2698
+ result = self ._data . array ._str_swapcase ()
2700
2699
return self ._wrap_result (result )
2701
2700
2702
2701
@Appender (_shared_docs ["casemethods" ] % _doc_args ["casefold" ])
2703
2702
@forbid_nonstring_types (["bytes" ])
2704
2703
def casefold (self ):
2705
- result = self ._array ._str_casefold ()
2704
+ result = self ._data . array ._str_casefold ()
2706
2705
return self ._wrap_result (result )
2707
2706
2708
2707
_shared_docs [
0 commit comments