@@ -74,6 +74,10 @@ def _str_map(
7474 na_value = self .dtype .na_value # type: ignore[attr-defined]
7575
7676 if not len (self ):
77+ if dtype == "Int64" :
78+ from pandas .core .construction import array as pd_array
79+
80+ return pd_array ([], dtype = dtype )
7781 return np .array ([], dtype = dtype )
7882
7983 arr = np .asarray (self , dtype = object )
@@ -110,12 +114,17 @@ def g(x):
110114 np .putmask (result , mask , na_value )
111115 if convert and result .dtype == object :
112116 result = lib .maybe_convert_objects (result )
117+
118+ if dtype == "Int64" :
119+ from pandas .core .construction import array as pd_array
120+
121+ return pd_array (result , dtype = dtype )
113122 return result
114123
115124 def _str_count (self , pat , flags : int = 0 ):
116125 regex = re .compile (pat , flags = flags )
117126 f = lambda x : len (regex .findall (x ))
118- return self ._str_map (f , dtype = "int64 " )
127+ return self ._str_map (f , dtype = "Int64 " )
119128
120129 def _str_pad (
121130 self ,
@@ -298,7 +307,7 @@ def _str_find_(self, sub, start, end, side):
298307 f = lambda x : getattr (x , method )(sub , start )
299308 else :
300309 f = lambda x : getattr (x , method )(sub , start , end )
301- return self ._str_map (f , dtype = "int64 " )
310+ return self ._str_map (f , dtype = "Int64 " )
302311
303312 def _str_findall (self , pat , flags : int = 0 ):
304313 regex = re .compile (pat , flags = flags )
@@ -319,14 +328,14 @@ def _str_index(self, sub, start: int = 0, end=None):
319328 f = lambda x : x .index (sub , start , end )
320329 else :
321330 f = lambda x : x .index (sub , start , end )
322- return self ._str_map (f , dtype = "int64 " )
331+ return self ._str_map (f , dtype = "Int64 " )
323332
324333 def _str_rindex (self , sub , start : int = 0 , end = None ):
325334 if end :
326335 f = lambda x : x .rindex (sub , start , end )
327336 else :
328337 f = lambda x : x .rindex (sub , start , end )
329- return self ._str_map (f , dtype = "int64 " )
338+ return self ._str_map (f , dtype = "Int64 " )
330339
331340 def _str_join (self , sep : str ):
332341 return self ._str_map (sep .join )
@@ -339,7 +348,7 @@ def _str_rpartition(self, sep: str, expand):
339348 return self ._str_map (lambda x : x .rpartition (sep ), dtype = "object" )
340349
341350 def _str_len (self ):
342- return self ._str_map (len , dtype = "int64 " )
351+ return self ._str_map (len , dtype = "Int64 " )
343352
344353 def _str_slice (self , start = None , stop = None , step = None ):
345354 obj = slice (start , stop , step )
0 commit comments