@@ -109,7 +109,7 @@ def wrapper(self, *args, **kwargs):
109
109
def _map_and_wrap (name , docstring ):
110
110
@forbid_nonstring_types (["bytes" ], name = name )
111
111
def wrapper (self ):
112
- result = getattr (self ._array , f"_str_{ name } " )()
112
+ result = getattr (self ._data . array , f"_str_{ name } " )()
113
113
return self ._wrap_result (result )
114
114
115
115
wrapper .__doc__ = docstring
@@ -154,8 +154,7 @@ def __init__(self, data):
154
154
self ._inferred_dtype = self ._validate (data )
155
155
self ._is_categorical = is_categorical_dtype (data .dtype )
156
156
self ._is_string = isinstance (data .dtype , StringDtype )
157
- array = data .array
158
- self ._array = array
157
+ self ._data = data
159
158
160
159
self ._index = self ._name = None
161
160
if isinstance (data , ABCSeries ):
@@ -219,7 +218,7 @@ def _validate(data):
219
218
return inferred_dtype
220
219
221
220
def __getitem__ (self , key ):
222
- result = self ._array ._str_getitem (key )
221
+ result = self ._data . array ._str_getitem (key )
223
222
return self ._wrap_result (result )
224
223
225
224
def __iter__ (self ):
@@ -744,13 +743,13 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
744
743
@Appender (_shared_docs ["str_split" ] % {"side" : "beginning" , "method" : "split" })
745
744
@forbid_nonstring_types (["bytes" ])
746
745
def split (self , pat = None , n = - 1 , expand = False ):
747
- result = self ._array ._str_split (pat , n , expand )
746
+ result = self ._data . array ._str_split (pat , n , expand )
748
747
return self ._wrap_result (result , returns_string = expand , expand = expand )
749
748
750
749
@Appender (_shared_docs ["str_split" ] % {"side" : "end" , "method" : "rsplit" })
751
750
@forbid_nonstring_types (["bytes" ])
752
751
def rsplit (self , pat = None , n = - 1 , expand = False ):
753
- result = self ._array ._str_rsplit (pat , n = n )
752
+ result = self ._data . array ._str_rsplit (pat , n = n )
754
753
return self ._wrap_result (result , expand = expand , returns_string = expand )
755
754
756
755
_shared_docs [
@@ -846,7 +845,7 @@ def rsplit(self, pat=None, n=-1, expand=False):
846
845
)
847
846
@forbid_nonstring_types (["bytes" ])
848
847
def partition (self , sep = " " , expand = True ):
849
- result = self ._array ._str_partition (sep , expand )
848
+ result = self ._data . array ._str_partition (sep , expand )
850
849
return self ._wrap_result (result , expand = expand , returns_string = expand )
851
850
852
851
@Appender (
@@ -860,7 +859,7 @@ def partition(self, sep=" ", expand=True):
860
859
)
861
860
@forbid_nonstring_types (["bytes" ])
862
861
def rpartition (self , sep = " " , expand = True ):
863
- result = self ._array ._str_rpartition (sep , expand )
862
+ result = self ._data . array ._str_rpartition (sep , expand )
864
863
return self ._wrap_result (result , expand = expand , returns_string = expand )
865
864
866
865
def get (self , i ):
@@ -914,7 +913,7 @@ def get(self, i):
914
913
5 None
915
914
dtype: object
916
915
"""
917
- result = self ._array ._str_get (i )
916
+ result = self ._data . array ._str_get (i )
918
917
return self ._wrap_result (result )
919
918
920
919
@forbid_nonstring_types (["bytes" ])
@@ -980,7 +979,7 @@ def join(self, sep):
980
979
4 NaN
981
980
dtype: object
982
981
"""
983
- result = self ._array ._str_join (sep )
982
+ result = self ._data . array ._str_join (sep )
984
983
return self ._wrap_result (result )
985
984
986
985
@forbid_nonstring_types (["bytes" ])
@@ -1108,7 +1107,7 @@ def contains(self, pat, case=True, flags=0, na=None, regex=True):
1108
1107
4 False
1109
1108
dtype: bool
1110
1109
"""
1111
- result = self ._array ._str_contains (pat , case , flags , na , regex )
1110
+ result = self ._data . array ._str_contains (pat , case , flags , na , regex )
1112
1111
return self ._wrap_result (result , fill_value = na , returns_string = False )
1113
1112
1114
1113
@forbid_nonstring_types (["bytes" ])
@@ -1140,7 +1139,7 @@ def match(self, pat, case=True, flags=0, na=None):
1140
1139
re.match.
1141
1140
extract : Extract matched groups.
1142
1141
"""
1143
- result = self ._array ._str_match (pat , case = case , flags = flags , na = na )
1142
+ result = self ._data . array ._str_match (pat , case = case , flags = flags , na = na )
1144
1143
return self ._wrap_result (result , fill_value = na , returns_string = False )
1145
1144
1146
1145
@forbid_nonstring_types (["bytes" ])
@@ -1173,7 +1172,7 @@ def fullmatch(self, pat, case=True, flags=0, na=None):
1173
1172
matches the regular expression.
1174
1173
extract : Extract matched groups.
1175
1174
"""
1176
- result = self ._array ._str_fullmatch (pat , case = case , flags = flags , na = na )
1175
+ result = self ._data . array ._str_fullmatch (pat , case = case , flags = flags , na = na )
1177
1176
return self ._wrap_result (result , fill_value = na , returns_string = False )
1178
1177
1179
1178
@forbid_nonstring_types (["bytes" ])
@@ -1309,7 +1308,7 @@ def replace(self, pat, repl, n=-1, case=None, flags=0, regex=None):
1309
1308
)
1310
1309
warnings .warn (msg , FutureWarning , stacklevel = 3 )
1311
1310
regex = True
1312
- result = self ._array ._str_replace (
1311
+ result = self ._data . array ._str_replace (
1313
1312
pat , repl , n = n , case = case , flags = flags , regex = regex
1314
1313
)
1315
1314
return self ._wrap_result (result )
@@ -1355,7 +1354,7 @@ def repeat(self, repeats):
1355
1354
2 ccc
1356
1355
dtype: object
1357
1356
"""
1358
- result = self ._array ._str_repeat (repeats )
1357
+ result = self ._data . array ._str_repeat (repeats )
1359
1358
return self ._wrap_result (result )
1360
1359
1361
1360
@forbid_nonstring_types (["bytes" ])
@@ -1423,7 +1422,7 @@ def pad(self, width, side="left", fillchar=" "):
1423
1422
msg = f"width must be of integer type, not { type (width ).__name__ } "
1424
1423
raise TypeError (msg )
1425
1424
1426
- result = self ._array ._str_pad (width , side = side , fillchar = fillchar )
1425
+ result = self ._data . array ._str_pad (width , side = side , fillchar = fillchar )
1427
1426
return self ._wrap_result (result )
1428
1427
1429
1428
_shared_docs [
@@ -1597,7 +1596,7 @@ def slice(self, start=None, stop=None, step=None):
1597
1596
2 cm
1598
1597
dtype: object
1599
1598
"""
1600
- result = self ._array ._str_slice (start , stop , step )
1599
+ result = self ._data . array ._str_slice (start , stop , step )
1601
1600
return self ._wrap_result (result )
1602
1601
1603
1602
@forbid_nonstring_types (["bytes" ])
@@ -1673,7 +1672,7 @@ def slice_replace(self, start=None, stop=None, repl=None):
1673
1672
4 aXde
1674
1673
dtype: object
1675
1674
"""
1676
- result = self ._array ._str_slice_replace (start , stop , repl )
1675
+ result = self ._data . array ._str_slice_replace (start , stop , repl )
1677
1676
return self ._wrap_result (result )
1678
1677
1679
1678
def decode (self , encoding , errors = "strict" ):
@@ -1699,7 +1698,7 @@ def decode(self, encoding, errors="strict"):
1699
1698
else :
1700
1699
decoder = codecs .getdecoder (encoding )
1701
1700
f = lambda x : decoder (x , errors )[0 ]
1702
- arr = self ._array
1701
+ arr = self ._data . array
1703
1702
# assert isinstance(arr, (StringArray,))
1704
1703
result = arr ._str_map (f )
1705
1704
return self ._wrap_result (result )
@@ -1720,7 +1719,7 @@ def encode(self, encoding, errors="strict"):
1720
1719
-------
1721
1720
encoded : Series/Index of objects
1722
1721
"""
1723
- result = self ._array ._str_encode (encoding , errors )
1722
+ result = self ._data . array ._str_encode (encoding , errors )
1724
1723
return self ._wrap_result (result , returns_string = False )
1725
1724
1726
1725
_shared_docs [
@@ -1798,7 +1797,7 @@ def encode(self, encoding, errors="strict"):
1798
1797
)
1799
1798
@forbid_nonstring_types (["bytes" ])
1800
1799
def strip (self , to_strip = None ):
1801
- result = self ._array ._str_strip (to_strip )
1800
+ result = self ._data . array ._str_strip (to_strip )
1802
1801
return self ._wrap_result (result )
1803
1802
1804
1803
@Appender (
@@ -1807,7 +1806,7 @@ def strip(self, to_strip=None):
1807
1806
)
1808
1807
@forbid_nonstring_types (["bytes" ])
1809
1808
def lstrip (self , to_strip = None ):
1810
- result = self ._array ._str_lstrip (to_strip )
1809
+ result = self ._data . array ._str_lstrip (to_strip )
1811
1810
return self ._wrap_result (result )
1812
1811
1813
1812
@Appender (
@@ -1816,7 +1815,7 @@ def lstrip(self, to_strip=None):
1816
1815
)
1817
1816
@forbid_nonstring_types (["bytes" ])
1818
1817
def rstrip (self , to_strip = None ):
1819
- result = self ._array ._str_rstrip (to_strip )
1818
+ result = self ._data . array ._str_rstrip (to_strip )
1820
1819
return self ._wrap_result (result )
1821
1820
1822
1821
@forbid_nonstring_types (["bytes" ])
@@ -1875,7 +1874,7 @@ def wrap(self, width, **kwargs):
1875
1874
1 another line\nto be\nwrapped
1876
1875
dtype: object
1877
1876
"""
1878
- result = self ._array ._str_wrap (width , ** kwargs )
1877
+ result = self ._data . array ._str_wrap (width , ** kwargs )
1879
1878
return self ._wrap_result (result )
1880
1879
1881
1880
@forbid_nonstring_types (["bytes" ])
@@ -1917,7 +1916,7 @@ def get_dummies(self, sep="|"):
1917
1916
"""
1918
1917
# we need to cast to Series of strings as only that has all
1919
1918
# methods available for making the dummies...
1920
- result , name = self ._array ._str_get_dummies (sep )
1919
+ result , name = self ._data . array ._str_get_dummies (sep )
1921
1920
return self ._wrap_result (
1922
1921
result ,
1923
1922
name = name ,
@@ -1944,7 +1943,7 @@ def translate(self, table):
1944
1943
-------
1945
1944
Series or Index
1946
1945
"""
1947
- result = self ._array ._str_translate (table )
1946
+ result = self ._data . array ._str_translate (table )
1948
1947
return self ._wrap_result (result )
1949
1948
1950
1949
@forbid_nonstring_types (["bytes" ])
@@ -2012,7 +2011,7 @@ def count(self, pat, flags=0):
2012
2011
>>> pd.Index(['A', 'A', 'Aaba', 'cat']).str.count('a')
2013
2012
Int64Index([0, 0, 2, 1], dtype='int64')
2014
2013
"""
2015
- result = self ._array ._str_count (pat , flags )
2014
+ result = self ._data . array ._str_count (pat , flags )
2016
2015
return self ._wrap_result (result , returns_string = False )
2017
2016
2018
2017
@forbid_nonstring_types (["bytes" ])
@@ -2069,7 +2068,7 @@ def startswith(self, pat, na=None):
2069
2068
3 False
2070
2069
dtype: bool
2071
2070
"""
2072
- result = self ._array ._str_startswith (pat , na = na )
2071
+ result = self ._data . array ._str_startswith (pat , na = na )
2073
2072
return self ._wrap_result (result , returns_string = False )
2074
2073
2075
2074
@forbid_nonstring_types (["bytes" ])
@@ -2126,7 +2125,7 @@ def endswith(self, pat, na=None):
2126
2125
3 False
2127
2126
dtype: bool
2128
2127
"""
2129
- result = self ._array ._str_endswith (pat , na = na )
2128
+ result = self ._data . array ._str_endswith (pat , na = na )
2130
2129
return self ._wrap_result (result , returns_string = False )
2131
2130
2132
2131
@forbid_nonstring_types (["bytes" ])
@@ -2219,7 +2218,7 @@ def findall(self, pat, flags=0):
2219
2218
2 [b, b]
2220
2219
dtype: object
2221
2220
"""
2222
- result = self ._array ._str_findall (pat , flags )
2221
+ result = self ._data . array ._str_findall (pat , flags )
2223
2222
return self ._wrap_result (result , returns_string = False )
2224
2223
2225
2224
@forbid_nonstring_types (["bytes" ])
@@ -2426,7 +2425,7 @@ def find(self, sub, start=0, end=None):
2426
2425
msg = f"expected a string object, not { type (sub ).__name__ } "
2427
2426
raise TypeError (msg )
2428
2427
2429
- result = self ._array ._str_find (sub , start , end )
2428
+ result = self ._data . array ._str_find (sub , start , end )
2430
2429
return self ._wrap_result (result , returns_string = False )
2431
2430
2432
2431
@Appender (
@@ -2443,7 +2442,7 @@ def rfind(self, sub, start=0, end=None):
2443
2442
msg = f"expected a string object, not { type (sub ).__name__ } "
2444
2443
raise TypeError (msg )
2445
2444
2446
- result = self ._array ._str_rfind (sub , start = start , end = end )
2445
+ result = self ._data . array ._str_rfind (sub , start = start , end = end )
2447
2446
return self ._wrap_result (result , returns_string = False )
2448
2447
2449
2448
@forbid_nonstring_types (["bytes" ])
@@ -2463,7 +2462,7 @@ def normalize(self, form):
2463
2462
-------
2464
2463
normalized : Series/Index of objects
2465
2464
"""
2466
- result = self ._array ._str_normalize (form )
2465
+ result = self ._data . array ._str_normalize (form )
2467
2466
return self ._wrap_result (result )
2468
2467
2469
2468
_shared_docs [
@@ -2510,7 +2509,7 @@ def index(self, sub, start=0, end=None):
2510
2509
msg = f"expected a string object, not { type (sub ).__name__ } "
2511
2510
raise TypeError (msg )
2512
2511
2513
- result = self ._array ._str_index (sub , start = start , end = end )
2512
+ result = self ._data . array ._str_index (sub , start = start , end = end )
2514
2513
return self ._wrap_result (result , returns_string = False )
2515
2514
2516
2515
@Appender (
@@ -2528,7 +2527,7 @@ def rindex(self, sub, start=0, end=None):
2528
2527
msg = f"expected a string object, not { type (sub ).__name__ } "
2529
2528
raise TypeError (msg )
2530
2529
2531
- result = self ._array ._str_rindex (sub , start = start , end = end )
2530
+ result = self ._data . array ._str_rindex (sub , start = start , end = end )
2532
2531
return self ._wrap_result (result , returns_string = False )
2533
2532
2534
2533
def len (self ):
@@ -2577,7 +2576,7 @@ def len(self):
2577
2576
5 3.0
2578
2577
dtype: float64
2579
2578
"""
2580
- result = self ._array ._str_len ()
2579
+ result = self ._data . array ._str_len ()
2581
2580
return self ._wrap_result (result , returns_string = False )
2582
2581
2583
2582
_shared_docs [
@@ -2677,37 +2676,37 @@ def len(self):
2677
2676
@Appender (_shared_docs ["casemethods" ] % _doc_args ["lower" ])
2678
2677
@forbid_nonstring_types (["bytes" ])
2679
2678
def lower (self ):
2680
- result = self ._array ._str_lower ()
2679
+ result = self ._data . array ._str_lower ()
2681
2680
return self ._wrap_result (result )
2682
2681
2683
2682
@Appender (_shared_docs ["casemethods" ] % _doc_args ["upper" ])
2684
2683
@forbid_nonstring_types (["bytes" ])
2685
2684
def upper (self ):
2686
- result = self ._array ._str_upper ()
2685
+ result = self ._data . array ._str_upper ()
2687
2686
return self ._wrap_result (result )
2688
2687
2689
2688
@Appender (_shared_docs ["casemethods" ] % _doc_args ["title" ])
2690
2689
@forbid_nonstring_types (["bytes" ])
2691
2690
def title (self ):
2692
- result = self ._array ._str_title ()
2691
+ result = self ._data . array ._str_title ()
2693
2692
return self ._wrap_result (result )
2694
2693
2695
2694
@Appender (_shared_docs ["casemethods" ] % _doc_args ["capitalize" ])
2696
2695
@forbid_nonstring_types (["bytes" ])
2697
2696
def capitalize (self ):
2698
- result = self ._array ._str_capitalize ()
2697
+ result = self ._data . array ._str_capitalize ()
2699
2698
return self ._wrap_result (result )
2700
2699
2701
2700
@Appender (_shared_docs ["casemethods" ] % _doc_args ["swapcase" ])
2702
2701
@forbid_nonstring_types (["bytes" ])
2703
2702
def swapcase (self ):
2704
- result = self ._array ._str_swapcase ()
2703
+ result = self ._data . array ._str_swapcase ()
2705
2704
return self ._wrap_result (result )
2706
2705
2707
2706
@Appender (_shared_docs ["casemethods" ] % _doc_args ["casefold" ])
2708
2707
@forbid_nonstring_types (["bytes" ])
2709
2708
def casefold (self ):
2710
- result = self ._array ._str_casefold ()
2709
+ result = self ._data . array ._str_casefold ()
2711
2710
return self ._wrap_result (result )
2712
2711
2713
2712
_shared_docs [
0 commit comments