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

Implement Series.size in new style #217

Merged
merged 1 commit into from
Oct 16, 2019
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
31 changes: 31 additions & 0 deletions hpat/datatypes/hpat_pandas_series_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,37 @@ def hpat_pandas_series_index_impl(self):
return hpat_pandas_series_index_impl


@overload_attribute(SeriesType, 'size')
def hpat_pandas_series_size(self):
"""
Pandas Series attribute :attr:`pandas.Series.size` implementation

.. only:: developer

Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_size

Parameters
----------
series: :obj:`pandas.Series`
input series

Returns
-------
:class:`pandas.Series`
Return the number of elements in the underlying data.
"""

_func_name = 'Attribute size.'

if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))

def hpat_pandas_series_size_impl(self):
return len(self._data)

return hpat_pandas_series_size_impl


@overload(len)
def hpat_pandas_series_len(self):
"""
Expand Down
17 changes: 12 additions & 5 deletions hpat/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,21 @@ def test_impl(A):
S = pd.Series([3, 5, 6], ['a', 'b', 'c'], name='A')
pd.testing.assert_series_equal(hpat_func(S), test_impl(S))

def test_series_attr1(self):
def test_impl(A):
return A.size
def test_series_size(self):
PokhodenkoSA marked this conversation as resolved.
Show resolved Hide resolved
def test_impl(S):
return S.size
hpat_func = hpat.jit(test_impl)

n = 11
df = pd.DataFrame({'A': np.arange(n)})
self.assertEqual(hpat_func(df.A), test_impl(df.A))
for S, expected in [
(pd.Series(), 0),
(pd.Series(np.arange(n)), n),
(pd.Series([np.nan, 1, 2]), 3),
(pd.Series(['1', '2', '3']), 3),
]:
with self.subTest(S=S, expected=expected):
self.assertEqual(hpat_func(S), expected)
self.assertEqual(hpat_func(S), test_impl(S))

def test_series_attr2(self):
def test_impl(A):
Expand Down