1010
1111import numpy as np
1212
13+ from pandas ._libs import lib
1314from pandas .compat import (
1415 pa_version_under10p1 ,
1516 pa_version_under11p0 ,
1617 pa_version_under13p0 ,
1718 pa_version_under17p0 ,
1819)
1920
20- from pandas .core .dtypes .missing import isna
21-
2221if not pa_version_under10p1 :
2322 import pyarrow as pa
2423 import pyarrow .compute as pc
@@ -38,7 +37,7 @@ class ArrowStringArrayMixin:
3837 def __init__ (self , * args , ** kwargs ) -> None :
3938 raise NotImplementedError
4039
41- def _convert_bool_result (self , result ):
40+ def _convert_bool_result (self , result , na = lib . no_default , method_name = None ):
4241 # Convert a bool-dtype result to the appropriate result type
4342 raise NotImplementedError
4443
@@ -212,7 +211,9 @@ def _str_removesuffix(self, suffix: str):
212211 result = pc .if_else (ends_with , removed , self ._pa_array )
213212 return type (self )(result )
214213
215- def _str_startswith (self , pat : str | tuple [str , ...], na : Scalar | None = None ):
214+ def _str_startswith (
215+ self , pat : str | tuple [str , ...], na : Scalar | lib .NoDefault = lib .no_default
216+ ):
216217 if isinstance (pat , str ):
217218 result = pc .starts_with (self ._pa_array , pattern = pat )
218219 else :
@@ -225,11 +226,11 @@ def _str_startswith(self, pat: str | tuple[str, ...], na: Scalar | None = None):
225226
226227 for p in pat [1 :]:
227228 result = pc .or_ (result , pc .starts_with (self ._pa_array , pattern = p ))
228- if not isna (na ): # pyright: ignore [reportGeneralTypeIssues]
229- result = result .fill_null (na )
230- return self ._convert_bool_result (result )
229+ return self ._convert_bool_result (result , na = na , method_name = "startswith" )
231230
232- def _str_endswith (self , pat : str | tuple [str , ...], na : Scalar | None = None ):
231+ def _str_endswith (
232+ self , pat : str | tuple [str , ...], na : Scalar | lib .NoDefault = lib .no_default
233+ ):
233234 if isinstance (pat , str ):
234235 result = pc .ends_with (self ._pa_array , pattern = pat )
235236 else :
@@ -242,9 +243,7 @@ def _str_endswith(self, pat: str | tuple[str, ...], na: Scalar | None = None):
242243
243244 for p in pat [1 :]:
244245 result = pc .or_ (result , pc .ends_with (self ._pa_array , pattern = p ))
245- if not isna (na ): # pyright: ignore [reportGeneralTypeIssues]
246- result = result .fill_null (na )
247- return self ._convert_bool_result (result )
246+ return self ._convert_bool_result (result , na = na , method_name = "endswith" )
248247
249248 def _str_isalnum (self ):
250249 result = pc .utf8_is_alnum (self ._pa_array )
@@ -283,7 +282,12 @@ def _str_isupper(self):
283282 return self ._convert_bool_result (result )
284283
285284 def _str_contains (
286- self , pat , case : bool = True , flags : int = 0 , na = None , regex : bool = True
285+ self ,
286+ pat ,
287+ case : bool = True ,
288+ flags : int = 0 ,
289+ na : Scalar | lib .NoDefault = lib .no_default ,
290+ regex : bool = True ,
287291 ):
288292 if flags :
289293 raise NotImplementedError (f"contains not implemented with { flags = } " )
@@ -293,19 +297,25 @@ def _str_contains(
293297 else :
294298 pa_contains = pc .match_substring
295299 result = pa_contains (self ._pa_array , pat , ignore_case = not case )
296- if not isna (na ): # pyright: ignore [reportGeneralTypeIssues]
297- result = result .fill_null (na )
298- return self ._convert_bool_result (result )
300+ return self ._convert_bool_result (result , na = na , method_name = "contains" )
299301
300302 def _str_match (
301- self , pat : str , case : bool = True , flags : int = 0 , na : Scalar | None = None
303+ self ,
304+ pat : str ,
305+ case : bool = True ,
306+ flags : int = 0 ,
307+ na : Scalar | lib .NoDefault = lib .no_default ,
302308 ):
303309 if not pat .startswith ("^" ):
304310 pat = f"^{ pat } "
305311 return self ._str_contains (pat , case , flags , na , regex = True )
306312
307313 def _str_fullmatch (
308- self , pat , case : bool = True , flags : int = 0 , na : Scalar | None = None
314+ self ,
315+ pat ,
316+ case : bool = True ,
317+ flags : int = 0 ,
318+ na : Scalar | lib .NoDefault = lib .no_default ,
309319 ):
310320 if not pat .endswith ("$" ) or pat .endswith ("\\ $" ):
311321 pat = f"{ pat } $"
0 commit comments