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

Commit d80cda0

Browse files
RubtsowaAlexanderKalistratov
authored andcommitted
Add isalnum (#454)
* start Impl * add example for isalnum * skip in SDC_CONFIG_PIPELINE_SDC=1, not supported * delete comment * add see also * correction doc * correction problem code style
1 parent ab29690 commit d80cda0

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-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_isalnum():
33+
series = pd.Series(['leopard', 'Golden Eagle', 'SNAKE', ''])
34+
out_series = series.str.isalnum()
35+
36+
return out_series # Expect series of True, False, True, False
37+
38+
39+
print(series_str_isalnum())

sdc/datatypes/hpat_pandas_stringmethods_functions.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,84 @@ def hpat_pandas_stringmethods_islower_impl(self):
12251225
return hpat_pandas_stringmethods_islower_impl
12261226

12271227

1228+
@overload_method(StringMethodsType, 'isalnum')
1229+
def hpat_pandas_stringmethods_isalnum(self):
1230+
"""
1231+
Intel Scalable Dataframe Compiler User Guide
1232+
********************************************
1233+
Pandas API: pandas.Series.str.isalnum
1234+
1235+
Limitations
1236+
-----------
1237+
Series elements are expected to be Unicode strings. Elements cannot be NaN.
1238+
1239+
Examples
1240+
--------
1241+
.. literalinclude:: ../../../examples/series/str/series_str_isalnum.py
1242+
:language: python
1243+
:lines: 27-
1244+
:caption: Check if all the characters in the text are alphanumeric
1245+
:name: ex_series_str_isalnum
1246+
1247+
.. command-output:: python ./series/str/series_str_isalnum.py
1248+
:cwd: ../../../examples
1249+
1250+
.. seealso::
1251+
:ref:`Series.str.isalpha <pandas.Series.str.isalpha>`
1252+
Check whether all characters are alphabetic.
1253+
:ref:`Series.str.isnumeric <pandas.Series.str.isnumeric>`
1254+
Check whether all characters are numeric.
1255+
:ref:`Series.str.isalnum <pandas.Series.str.isalnum>`
1256+
Check whether all characters are alphanumeric.
1257+
:ref:`Series.str.isdigit <pandas.Series.str.isdigit>`
1258+
Check whether all characters are digits.
1259+
:ref:`Series.str.isdecimal <pandas.Series.str.isdecimal>`
1260+
Check whether all characters are decimal.
1261+
:ref:`Series.str.isspace <pandas.Series.str.isspace>`
1262+
Check whether all characters are whitespace.
1263+
:ref:`Series.str.islower <pandas.Series.str.islower>`
1264+
Check whether all characters are lowercase.
1265+
:ref:`Series.str.isupper <pandas.Series.str.isupper>`
1266+
Check whether all characters are uppercase.
1267+
:ref:`Series.str.istitle <pandas.Series.str.istitle>`
1268+
Check whether all characters are titlecase.
1269+
1270+
Intel Scalable Dataframe Compiler Developer Guide
1271+
*************************************************
1272+
1273+
Pandas Series method :meth:`pandas.core.strings.StringMethods.isalnum()` implementation.
1274+
1275+
Note: Unicode type of list elements are supported only. Numpy.NaN is not supported as elements.
1276+
1277+
.. only:: developer
1278+
1279+
Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_isalnum_str
1280+
1281+
Parameters
1282+
----------
1283+
self: :class:`pandas.core.strings.StringMethods`
1284+
input arg
1285+
1286+
Returns
1287+
-------
1288+
:obj:`pandas.Series`
1289+
returns :obj:`pandas.Series` object
1290+
"""
1291+
1292+
ty_checker = TypeChecker('Method isalnum().')
1293+
ty_checker.check(self, StringMethodsType)
1294+
1295+
def hpat_pandas_stringmethods_isalnum_impl(self):
1296+
item_count = len(self._data)
1297+
result = numpy.empty(item_count, numba.types.boolean)
1298+
for idx, item in enumerate(self._data._data):
1299+
result[idx] = item.isalnum()
1300+
1301+
return pandas.Series(result, self._data._index, name=self._data._name)
1302+
1303+
return hpat_pandas_stringmethods_isalnum_impl
1304+
1305+
12281306
# _hpat_pandas_stringmethods_autogen_methods = sorted(dir(numba.types.misc.UnicodeType.__getattribute__.__qualname__))
12291307
_hpat_pandas_stringmethods_autogen_methods = ['upper', 'lower', 'lstrip', 'rstrip', 'strip']
12301308
"""

sdc/tests/test_series.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ def islower_usecase(series):
242242
return series.str.islower()
243243

244244

245+
def isalnum_usecase(series):
246+
return series.str.isalnum()
247+
248+
245249
GLOBAL_VAL = 2
246250

247251

@@ -5539,6 +5543,19 @@ def test_series_islower_str(self):
55395543
S = pd.Series(ser)
55405544
pd.testing.assert_series_equal(cfunc(S), islower_usecase(S))
55415545

5546+
@skip_sdc_jit("Series.str.isalnum is not supported yet")
5547+
def test_series_isalnum_str(self):
5548+
series = [['one', 'one1', '1', ''],
5549+
['A B', '1.5', '3,000'],
5550+
['23', '⅕', ''],
5551+
['leopard', 'Golden Eagle', 'SNAKE', '']
5552+
]
5553+
5554+
cfunc = self.jit(isalnum_usecase)
5555+
for ser in series:
5556+
S = pd.Series(ser)
5557+
pd.testing.assert_series_equal(cfunc(S), isalnum_usecase(S))
5558+
55425559

55435560
if __name__ == "__main__":
55445561
unittest.main()

0 commit comments

Comments
 (0)