Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/series/str/series_str_isspace.py
Original file line number Diff line number Diff line change
@@ -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_isspace():
series = pd.Series([' ', ' c ', ' b ', ' a '])
out_series = series.str.isspace()

return out_series # Expect series of True, False, False, False


print(series_str_isspace())
78 changes: 78 additions & 0 deletions sdc/datatypes/hpat_pandas_stringmethods_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,84 @@ def hpat_pandas_stringmethods_istitle_impl(self):
return hpat_pandas_stringmethods_istitle_impl


@overload_method(StringMethodsType, 'isspace')
def hpat_pandas_stringmethods_isspace(self):
"""
Intel Scalable Dataframe Compiler User Guide
********************************************
Pandas API: pandas.Series.str.isspace

Limitations
-----------
Series elements are expected to be Unicode strings. Elements cannot be NaN.

Examples
--------
.. literalinclude:: ../../../examples/series/str/series_str_isspace.py
:language: python
:lines: 27-
:caption: Check if all the characters in the text are whitespaces
:name: ex_series_str_isspace

.. command-output:: python ./series/str/series_str_isspace.py
:cwd: ../../../examples

.. seealso::
:ref:`Series.str.isalpha <pandas.Series.str.isalpha>`
Check whether all characters are alphabetic.
:ref:`Series.str.isnumeric <pandas.Series.str.isnumeric>`
Check whether all characters are numeric.
:ref:`Series.str.isalnum <pandas.Series.str.isalnum>`
Check whether all characters are alphanumeric.
:ref:`Series.str.isdigit <pandas.Series.str.isdigit>`
Check whether all characters are digits.
:ref:`Series.str.isdecimal <pandas.Series.str.isdecimal>`
Check whether all characters are decimal.
:ref:`Series.str.isspace <pandas.Series.str.isspace>`
Check whether all characters are whitespace.
:ref:`Series.str.islower <pandas.Series.str.islower>`
Check whether all characters are lowercase.
:ref:`Series.str.isupper <pandas.Series.str.isupper>`
Check whether all characters are uppercase.
:ref:`Series.str.istitle <pandas.Series.str.istitle>`
Check whether all characters are titlecase.

Intel Scalable Dataframe Compiler Developer Guide
*************************************************

Pandas Series method :meth:`pandas.core.strings.StringMethods.isspace()` 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_isspace_str

Parameters
----------
self: :class:`pandas.core.strings.StringMethods`
input arg

Returns
-------
:obj:`pandas.Series`
returns :obj:`pandas.Series` object
"""

ty_checker = TypeChecker('Method isspace().')
ty_checker.check(self, StringMethodsType)

def hpat_pandas_stringmethods_isspace_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.isspace()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be, it's better to cut result = numpy.array([item.isspace() for item in self._data._data])


return pandas.Series(result, self._data._index, name=self._data._name)

return hpat_pandas_stringmethods_isspace_impl


# _hpat_pandas_stringmethods_autogen_methods = sorted(dir(numba.types.misc.UnicodeType.__getattribute__.__qualname__))
_hpat_pandas_stringmethods_autogen_methods = ['upper', 'lower', 'lstrip', 'rstrip', 'strip']
"""
Expand Down
16 changes: 16 additions & 0 deletions sdc/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ def istitle_usecase(series):
return series.str.istitle()


def isspace_usecase(series):
return series.str.isspace()


GLOBAL_VAL = 2


Expand Down Expand Up @@ -5492,6 +5496,18 @@ def test_series_istitle_str(self):
cfunc = self.jit(istitle_usecase)
pd.testing.assert_series_equal(cfunc(series), istitle_usecase(series))

@skip_sdc_jit("Series.str.isspace is not supported yet")
def test_series_isspace_str(self):
series = [['', ' ', ' ', ' '],
['', ' c ', ' b ', ' a '],
['aaaaaa', 'bb', 'c', ' d']
]

cfunc = self.jit(isspace_usecase)
for ser in series:
S = pd.Series(ser)
pd.testing.assert_series_equal(cfunc(S), isspace_usecase(S))


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