@@ -89,6 +89,7 @@ def hpat_pandas_stringmethods_upper_impl(self):
8989from sdc .utilities .utils import sdc_overload_method , sdc_register_jitable
9090from sdc .hiframes .api import get_nan_mask
9191from sdc .str_arr_ext import str_arr_set_na_by_mask , create_str_arr_from_list
92+ from sdc .datatypes .common_functions import SDCLimitation
9293
9394
9495@sdc_overload_method (StringMethodsType , 'center' )
@@ -151,6 +152,87 @@ def hpat_pandas_stringmethods_center_impl(self, width, fillchar=' '):
151152 return hpat_pandas_stringmethods_center_impl
152153
153154
155+ @sdc_overload_method (StringMethodsType , 'contains' )
156+ def hpat_pandas_stringmethods_contains (self , pat , case = True , flags = 0 , na = None , regex = True ):
157+ """
158+ Intel Scalable Dataframe Compiler User Guide
159+ ********************************************
160+ Pandas API: pandas.Series.str.contains
161+
162+ Limitations
163+ -----------
164+ - Series elements are expected to be Unicode strings. Elements cannot be `NaNs`.
165+ - Parameter ``na`` is supported only with default value ``None``.
166+ - Parameter ``flags`` is supported only with default value ``0``.
167+ - Parameter ``regex`` is supported only with default value ``True``.
168+
169+ Examples
170+ --------
171+ .. literalinclude:: ../../../examples/series/str/series_str_contains.py
172+ :language: python
173+ :lines: 27-
174+ :caption: Tests if string element contains a pattern.
175+ :name: ex_series_str_contains
176+
177+ .. command-output:: python ./series/str/series_str_contains.py
178+ :cwd: ../../../examples
179+
180+ .. seealso::
181+ :ref:`Series.str.startswith <pandas.Series.str.startswith>`
182+ Same as endswith, but tests the start of string.
183+ :ref:`Series.str.endswith <pandas.Series.str.endswith>`
184+ Same as startswith, but tests the end of string.
185+
186+ Intel Scalable Dataframe Compiler Developer Guide
187+ *************************************************
188+
189+ Pandas Series method :meth:`pandas.core.strings.StringMethods.contains()` implementation.
190+
191+ .. only:: developer
192+
193+ Test: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_contains
194+ """
195+
196+ ty_checker = TypeChecker ('Method contains().' )
197+ ty_checker .check (self , StringMethodsType )
198+
199+ if not isinstance (pat , (StringLiteral , UnicodeType )):
200+ ty_checker .raise_exc (pat , 'str' , 'pat' )
201+
202+ if not isinstance (na , (Omitted , NoneType )) and na is not None :
203+ ty_checker .raise_exc (na , 'none' , 'na' )
204+
205+ if not isinstance (case , (Boolean , Omitted )) and case is not True :
206+ ty_checker .raise_exc (case , 'bool' , 'case' )
207+
208+ if not isinstance (flags , (Omitted , Integer )) and flags != 0 :
209+ ty_checker .raise_exc (flags , 'int64' , 'flags' )
210+
211+ if not isinstance (regex , (Omitted , Boolean )) and regex is not True :
212+ ty_checker .raise_exc (regex , 'bool' , 'regex' )
213+
214+ def hpat_pandas_stringmethods_contains_impl (self , pat , case = True , flags = 0 , na = None , regex = True ):
215+ if flags != 0 :
216+ raise SDCLimitation ("Method contains(). Unsupported parameter. Given 'flags' != 0" )
217+
218+ if not regex :
219+ raise SDCLimitation ("Method contains(). Unsupported parameter. Given 'regex' is False" )
220+
221+ if not case :
222+ _pat = pat .lower ()
223+ else :
224+ _pat = pat
225+
226+ len_data = len (self ._data )
227+ res_list = numpy .empty (len_data , numba .types .boolean )
228+ for idx in numba .prange (len_data ):
229+ res_list [idx ] = _pat in self ._data ._data [idx ]
230+
231+ return pandas .Series (res_list , self ._data ._index , name = self ._data ._name )
232+
233+ return hpat_pandas_stringmethods_contains_impl
234+
235+
154236@sdc_overload_method (StringMethodsType , 'endswith' )
155237def hpat_pandas_stringmethods_endswith (self , pat , na = None ):
156238 """
0 commit comments