diff --git a/examples/series/str/series_str_isalpha.py b/examples/series/str/series_str_isalpha.py new file mode 100644 index 000000000..67a7ca666 --- /dev/null +++ b/examples/series/str/series_str_isalpha.py @@ -0,0 +1,39 @@ +# ***************************************************************************** +# Copyright (c) 2019, Intel Corporation All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ***************************************************************************** + +import pandas as pd +from numba import njit + + +@njit +def series_str_isalpha(): + series = pd.Series(['leopard', 'Golden Eagle', 'SNAKE', '']) + out_series = series.str.isalpha() + + return out_series # Expect series of True, False, True, False + + +print(series_str_isalpha()) diff --git a/sdc/datatypes/hpat_pandas_stringmethods_functions.py b/sdc/datatypes/hpat_pandas_stringmethods_functions.py index 21778f2d1..9bf31b68c 100644 --- a/sdc/datatypes/hpat_pandas_stringmethods_functions.py +++ b/sdc/datatypes/hpat_pandas_stringmethods_functions.py @@ -1069,6 +1069,84 @@ def hpat_pandas_stringmethods_isspace_impl(self): return hpat_pandas_stringmethods_isspace_impl +@overload_method(StringMethodsType, 'isalpha') +def hpat_pandas_stringmethods_isalpha(self): + """ + Intel Scalable Dataframe Compiler User Guide + ******************************************** + Pandas API: pandas.Series.str.isalpha + + Limitations + ----------- + Series elements are expected to be Unicode strings. Elements cannot be NaN. + + Examples + -------- + .. literalinclude:: ../../../examples/series/str/series_str_isalpha.py + :language: python + :lines: 27- + :caption: Check whether all characters in each string are alphabetic. + :name: ex_series_str_isalpha + + .. command-output:: python ./series/str/series_str_isalpha.py + :cwd: ../../../examples + + .. seealso:: + :ref:`Series.str.isalpha ` + Check whether all characters are alphabetic. + :ref:`Series.str.isnumeric ` + Check whether all characters are numeric. + :ref:`Series.str.isalnum ` + Check whether all characters are alphanumeric. + :ref:`Series.str.isdigit ` + Check whether all characters are digits. + :ref:`Series.str.isdecimal ` + Check whether all characters are decimal. + :ref:`Series.str.isspace ` + Check whether all characters are whitespace. + :ref:`Series.str.islower ` + Check whether all characters are lowercase. + :ref:`Series.str.isupper ` + Check whether all characters are uppercase. + :ref:`Series.str.istitle ` + Check whether all characters are titlecase. + + Intel Scalable Dataframe Compiler Developer Guide + ************************************************* + + Pandas Series method :meth:`pandas.core.strings.StringMethods.isalpha()` implementation. + + Note: Unicode type of list elements are supported only. Numpy.NaN is not supported as elements. + + .. only:: developer + + Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_isalpha_str + + Parameters + ---------- + self: :class:`pandas.core.strings.StringMethods` + input arg + + Returns + ------- + :obj:`pandas.Series` + returns :obj:`pandas.Series` object + """ + + ty_checker = TypeChecker('Method isalpha().') + ty_checker.check(self, StringMethodsType) + + def hpat_pandas_stringmethods_isalpha_impl(self): + item_count = len(self._data) + result = numpy.empty(item_count, numba.types.boolean) + for idx, item in enumerate(self._data._data): + result[idx] = item.isalpha() + + return pandas.Series(result, self._data._index, name=self._data._name) + + return hpat_pandas_stringmethods_isalpha_impl + + # _hpat_pandas_stringmethods_autogen_methods = sorted(dir(numba.types.misc.UnicodeType.__getattribute__.__qualname__)) _hpat_pandas_stringmethods_autogen_methods = ['upper', 'lower', 'lstrip', 'rstrip', 'strip'] """ diff --git a/sdc/tests/test_series.py b/sdc/tests/test_series.py index 33ca69f2f..cd3744b35 100644 --- a/sdc/tests/test_series.py +++ b/sdc/tests/test_series.py @@ -234,6 +234,10 @@ def isspace_usecase(series): return series.str.isspace() +def isalpha_usecase(series): + return series.str.isalpha() + + GLOBAL_VAL = 2 @@ -5508,6 +5512,18 @@ def test_series_isspace_str(self): S = pd.Series(ser) pd.testing.assert_series_equal(cfunc(S), isspace_usecase(S)) + @skip_sdc_jit("Series.str.isalpha is not supported yet") + def test_series_isalpha_str(self): + series = [['leopard', 'Golden Eagle', 'SNAKE', ''], + ['Hello world!', 'hello 123', 'mynameisPeter'], + ['one', 'one1', '1', ''] + ] + + cfunc = self.jit(isalpha_usecase) + for ser in series: + S = pd.Series(ser) + pd.testing.assert_series_equal(cfunc(S), isalpha_usecase(S)) + if __name__ == "__main__": unittest.main()