Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 225a5c2

Browse files
RubtsowaAlexanderKalistratov
authored andcommitted
Add isalpha (#458)
* start Imp isalpha * add example and test * correction problem PEP8 * correction result merge * change * correction problem PEP8 * correction doc
1 parent 3782e01 commit 225a5c2

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2019, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
import pandas as pd
28+
from numba import njit
29+
30+
31+
@njit
32+
def series_str_isalpha():
33+
series = pd.Series(['leopard', 'Golden Eagle', 'SNAKE', ''])
34+
out_series = series.str.isalpha()
35+
36+
return out_series # Expect series of True, False, True, False
37+
38+
39+
print(series_str_isalpha())

sdc/datatypes/hpat_pandas_stringmethods_functions.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,84 @@ def hpat_pandas_stringmethods_isspace_impl(self):
10691069
return hpat_pandas_stringmethods_isspace_impl
10701070

10711071

1072+
@overload_method(StringMethodsType, 'isalpha')
1073+
def hpat_pandas_stringmethods_isalpha(self):
1074+
"""
1075+
Intel Scalable Dataframe Compiler User Guide
1076+
********************************************
1077+
Pandas API: pandas.Series.str.isalpha
1078+
1079+
Limitations
1080+
-----------
1081+
Series elements are expected to be Unicode strings. Elements cannot be NaN.
1082+
1083+
Examples
1084+
--------
1085+
.. literalinclude:: ../../../examples/series/str/series_str_isalpha.py
1086+
:language: python
1087+
:lines: 27-
1088+
:caption: Check whether all characters in each string are alphabetic.
1089+
:name: ex_series_str_isalpha
1090+
1091+
.. command-output:: python ./series/str/series_str_isalpha.py
1092+
:cwd: ../../../examples
1093+
1094+
.. seealso::
1095+
:ref:`Series.str.isalpha <pandas.Series.str.isalpha>`
1096+
Check whether all characters are alphabetic.
1097+
:ref:`Series.str.isnumeric <pandas.Series.str.isnumeric>`
1098+
Check whether all characters are numeric.
1099+
:ref:`Series.str.isalnum <pandas.Series.str.isalnum>`
1100+
Check whether all characters are alphanumeric.
1101+
:ref:`Series.str.isdigit <pandas.Series.str.isdigit>`
1102+
Check whether all characters are digits.
1103+
:ref:`Series.str.isdecimal <pandas.Series.str.isdecimal>`
1104+
Check whether all characters are decimal.
1105+
:ref:`Series.str.isspace <pandas.Series.str.isspace>`
1106+
Check whether all characters are whitespace.
1107+
:ref:`Series.str.islower <pandas.Series.str.islower>`
1108+
Check whether all characters are lowercase.
1109+
:ref:`Series.str.isupper <pandas.Series.str.isupper>`
1110+
Check whether all characters are uppercase.
1111+
:ref:`Series.str.istitle <pandas.Series.str.istitle>`
1112+
Check whether all characters are titlecase.
1113+
1114+
Intel Scalable Dataframe Compiler Developer Guide
1115+
*************************************************
1116+
1117+
Pandas Series method :meth:`pandas.core.strings.StringMethods.isalpha()` implementation.
1118+
1119+
Note: Unicode type of list elements are supported only. Numpy.NaN is not supported as elements.
1120+
1121+
.. only:: developer
1122+
1123+
Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_isalpha_str
1124+
1125+
Parameters
1126+
----------
1127+
self: :class:`pandas.core.strings.StringMethods`
1128+
input arg
1129+
1130+
Returns
1131+
-------
1132+
:obj:`pandas.Series`
1133+
returns :obj:`pandas.Series` object
1134+
"""
1135+
1136+
ty_checker = TypeChecker('Method isalpha().')
1137+
ty_checker.check(self, StringMethodsType)
1138+
1139+
def hpat_pandas_stringmethods_isalpha_impl(self):
1140+
item_count = len(self._data)
1141+
result = numpy.empty(item_count, numba.types.boolean)
1142+
for idx, item in enumerate(self._data._data):
1143+
result[idx] = item.isalpha()
1144+
1145+
return pandas.Series(result, self._data._index, name=self._data._name)
1146+
1147+
return hpat_pandas_stringmethods_isalpha_impl
1148+
1149+
10721150
# _hpat_pandas_stringmethods_autogen_methods = sorted(dir(numba.types.misc.UnicodeType.__getattribute__.__qualname__))
10731151
_hpat_pandas_stringmethods_autogen_methods = ['upper', 'lower', 'lstrip', 'rstrip', 'strip']
10741152
"""

sdc/tests/test_series.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ def isspace_usecase(series):
234234
return series.str.isspace()
235235

236236

237+
def isalpha_usecase(series):
238+
return series.str.isalpha()
239+
240+
237241
GLOBAL_VAL = 2
238242

239243

@@ -5508,6 +5512,18 @@ def test_series_isspace_str(self):
55085512
S = pd.Series(ser)
55095513
pd.testing.assert_series_equal(cfunc(S), isspace_usecase(S))
55105514

5515+
@skip_sdc_jit("Series.str.isalpha is not supported yet")
5516+
def test_series_isalpha_str(self):
5517+
series = [['leopard', 'Golden Eagle', 'SNAKE', ''],
5518+
['Hello world!', 'hello 123', 'mynameisPeter'],
5519+
['one', 'one1', '1', '']
5520+
]
5521+
5522+
cfunc = self.jit(isalpha_usecase)
5523+
for ser in series:
5524+
S = pd.Series(ser)
5525+
pd.testing.assert_series_equal(cfunc(S), isalpha_usecase(S))
5526+
55115527

55125528
if __name__ == "__main__":
55135529
unittest.main()

0 commit comments

Comments
 (0)