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

Commit ab29690

Browse files
RubtsowaAlexanderKalistratov
authored andcommitted
impl str.islower (#456)
* impl str.islower * correction problem PEP* * correction doc * deleted 1 excess blank line
1 parent 225a5c2 commit ab29690

File tree

3 files changed

+132
-0
lines changed

3 files changed

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

sdc/datatypes/hpat_pandas_stringmethods_functions.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,84 @@ def hpat_pandas_stringmethods_isalpha_impl(self):
11471147
return hpat_pandas_stringmethods_isalpha_impl
11481148

11491149

1150+
@overload_method(StringMethodsType, 'islower')
1151+
def hpat_pandas_stringmethods_islower(self):
1152+
"""
1153+
Intel Scalable Dataframe Compiler User Guide
1154+
********************************************
1155+
Pandas API: pandas.Series.str.islower
1156+
1157+
Limitations
1158+
-----------
1159+
Series elements are expected to be Unicode strings. Elements cannot be NaN.
1160+
1161+
Examples
1162+
--------
1163+
.. literalinclude:: ../../../examples/series/str/series_str_islower.py
1164+
:language: python
1165+
:lines: 27-
1166+
:caption: Check if all the characters in the text are alphanumeric
1167+
:name: ex_series_str_islower
1168+
1169+
.. command-output:: python ./series/str/series_str_islower.py
1170+
:cwd: ../../../examples
1171+
1172+
.. seealso::
1173+
:ref:`Series.str.isalpha <pandas.Series.str.isalpha>`
1174+
Check whether all characters are alphabetic.
1175+
:ref:`Series.str.isnumeric <pandas.Series.str.isnumeric>`
1176+
Check whether all characters are numeric.
1177+
:ref:`Series.str.isalnum <pandas.Series.str.isalnum>`
1178+
Check whether all characters are alphanumeric.
1179+
:ref:`Series.str.isdigit <pandas.Series.str.isdigit>`
1180+
Check whether all characters are digits.
1181+
:ref:`Series.str.isdecimal <pandas.Series.str.isdecimal>`
1182+
Check whether all characters are decimal.
1183+
:ref:`Series.str.isspace <pandas.Series.str.isspace>`
1184+
Check whether all characters are whitespace.
1185+
:ref:`Series.str.islower <pandas.Series.str.islower>`
1186+
Check whether all characters are lowercase.
1187+
:ref:`Series.str.isupper <pandas.Series.str.isupper>`
1188+
Check whether all characters are uppercase.
1189+
:ref:`Series.str.istitle <pandas.Series.str.istitle>`
1190+
Check whether all characters are titlecase.
1191+
1192+
Intel Scalable Dataframe Compiler Developer Guide
1193+
*************************************************
1194+
1195+
Pandas Series method :meth:`pandas.core.strings.StringMethods.islower()` implementation.
1196+
1197+
Note: Unicode type of list elements are supported only. Numpy.NaN is not supported as elements.
1198+
1199+
.. only:: developer
1200+
1201+
Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_islower_str
1202+
1203+
Parameters
1204+
----------
1205+
self: :class:`pandas.core.strings.StringMethods`
1206+
input arg
1207+
1208+
Returns
1209+
-------
1210+
:obj:`pandas.Series`
1211+
returns :obj:`pandas.Series` object
1212+
"""
1213+
1214+
ty_checker = TypeChecker('Method islower().')
1215+
ty_checker.check(self, StringMethodsType)
1216+
1217+
def hpat_pandas_stringmethods_islower_impl(self):
1218+
item_count = len(self._data)
1219+
result = numpy.empty(item_count, numba.types.boolean)
1220+
for idx, item in enumerate(self._data._data):
1221+
result[idx] = item.islower()
1222+
1223+
return pandas.Series(result, self._data._index, name=self._data._name)
1224+
1225+
return hpat_pandas_stringmethods_islower_impl
1226+
1227+
11501228
# _hpat_pandas_stringmethods_autogen_methods = sorted(dir(numba.types.misc.UnicodeType.__getattribute__.__qualname__))
11511229
_hpat_pandas_stringmethods_autogen_methods = ['upper', 'lower', 'lstrip', 'rstrip', 'strip']
11521230
"""

sdc/tests/test_series.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ def isalpha_usecase(series):
238238
return series.str.isalpha()
239239

240240

241+
def islower_usecase(series):
242+
return series.str.islower()
243+
244+
241245
GLOBAL_VAL = 2
242246

243247

@@ -5524,6 +5528,17 @@ def test_series_isalpha_str(self):
55245528
S = pd.Series(ser)
55255529
pd.testing.assert_series_equal(cfunc(S), isalpha_usecase(S))
55265530

5531+
@skip_sdc_jit("Series.str.islower is not supported yet")
5532+
def test_series_islower_str(self):
5533+
series = [['leopard', 'Golden Eagle', 'SNAKE', ''],
5534+
['Hello world!', 'hello 123', 'mynameisPeter']
5535+
]
5536+
5537+
cfunc = self.jit(islower_usecase)
5538+
for ser in series:
5539+
S = pd.Series(ser)
5540+
pd.testing.assert_series_equal(cfunc(S), islower_usecase(S))
5541+
55275542

55285543
if __name__ == "__main__":
55295544
unittest.main()

0 commit comments

Comments
 (0)