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

Commit

Permalink
Merge 4eaae30 into 902ea10
Browse files Browse the repository at this point in the history
  • Loading branch information
1e-to committed Oct 24, 2019
2 parents 902ea10 + 4eaae30 commit 0aefaaa
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
48 changes: 48 additions & 0 deletions hpat/datatypes/hpat_pandas_series_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,54 @@ def hpat_pandas_series_copy_impl(self, deep=True):
return hpat_pandas_series_copy_impl


# @overload_method(SeriesType, 'head')
# def hpat_pandas_series_head(self, n=5):
# """
# Pandas Series method :meth:`pandas.Series.head` implementation.
#
# .. only:: developer
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head1
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_default1
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_index1
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_index2
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_index3
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_index4
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_parallel1
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_index_parallel1
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_index_parallel2
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_noidx
# Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_head_idx
#
# Parameters
# -----------
# n: :obj:`int`
# input argument, default 5
# Returns
# -------
# :obj:`pandas.Series`
# returns The first n rows of the caller object.
# """
#
# _func_name = 'Method head().'
#
# if not isinstance(self, SeriesType):
# raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
#
# if not isinstance(n, (types.Integer, types.Omitted)) and n != 5:
# raise TypingError('{} The parameter must be an integer type. Given type n: {}'.format(_func_name, n))
#
# if isinstance(self.index, types.NoneType):
# def hpat_pandas_series_head_impl(self, n=5):
# return pandas.Series(self._data[:n])
#
# return hpat_pandas_series_head_impl
# else:
# def hpat_pandas_series_head_index_impl(self, n=5):
# return pandas.Series(self._data[:n], self._index[:n])
#
# return hpat_pandas_series_head_index_impl


@overload_method(SeriesType, 'groupby')
def hpat_pandas_series_groupby(
self,
Expand Down
1 change: 1 addition & 0 deletions hpat/hiframes/pd_series_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ def generic_expand_cumulative_series(self, args, kws):
'resolve_take', 'resolve_max', 'resolve_min', 'resolve_nunique',
'resolve_prod', 'resolve_count']


# use ArrayAttribute for attributes not defined in SeriesAttribute
for attr, func in numba.typing.arraydecl.ArrayAttribute.__dict__.items():
if (attr.startswith('resolve_')
Expand Down
64 changes: 64 additions & 0 deletions hpat/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,70 @@ def test_impl(S):
pd.testing.assert_series_equal(hpat_func(S[start:end]), test_impl(S))
self.assertTrue(count_array_OneDs() > 0)

def test_series_head_noidx(self):
def test_impl(S):
return S.head()

def test_impl_param(S, n):
return S.head(n)

hpat_func = hpat.jit(test_impl)

data_test = [[6, 6, 2, 1, 3, 3, 2, 1, 2],
[1.1, 0.3, 2.1, 1, 3, 0.3, 2.1, 1.1, 2.2],
[6, 6.1, 2.2, 1, 3, 0, 2.2, 1, 2],
['as', 'b', 'abb', 'sss', 'ytr65', '', 'qw', 'a', 'b'],
[6, 6, 2, 1, 3, np.inf, np.nan, np.nan, np.nan],
[3., 5.3, np.nan, np.nan, np.inf, np.inf, 4.4, 3.7, 8.9]
]

for input_data in data_test:
S = pd.Series(input_data)

result_ref = test_impl(S)
result = hpat_func(S)
pd.testing.assert_series_equal(result, result_ref)

hpat_func_param1 = hpat.jit(test_impl_param)

for param1 in [0, 3, 10]:
result_param1_ref = test_impl_param(S, param1)
result_param1 = hpat_func_param1(S, param1)
pd.testing.assert_series_equal(result_param1, result_param1_ref)

@unittest.skip("Broke another three tests")
def test_series_head_idx(self):
def test_impl(S):
return S.head()

def test_impl_param(S, n):
return S.head(n)

hpat_func = hpat.jit(test_impl)

data_test = [[6, 6, 2, 1, 3, 3, 2, 1, 2],
[1.1, 0.3, 2.1, 1, 3, 0.3, 2.1, 1.1, 2.2],
[6, 6.1, 2.2, 1, 3, 0, 2.2, 1, 2],
['as', 'b', 'abb', 'sss', 'ytr65', '', 'qw', 'a', 'b'],
[6, 6, 2, 1, 3, np.inf, np.nan, np.nan, np.nan],
[3., 5.3, np.nan, np.nan, np.inf, np.inf, 4.4, 3.7, 8.9]
]

for input_data in data_test:
for index_data in data_test:
S = pd.Series(input_data, index_data)

result_ref = test_impl(S)
result = hpat_func(S)
pd.testing.assert_series_equal(result, result_ref)

hpat_func_param1 = hpat.jit(test_impl_param)

for param1 in [1, 3, 7]:
result_param1_ref = test_impl_param(S, param1)
result_param1 = hpat_func_param1(S, param1)
pd.testing.assert_series_equal(result_param1, result_param1_ref)

def test_series_median1(self):
'''Verifies median implementation for float and integer series of random data'''
def test_impl(S):
Expand Down

0 comments on commit 0aefaaa

Please sign in to comment.