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

Commit

Permalink
Minor changes for series.var()
Browse files Browse the repository at this point in the history
  • Loading branch information
densmirn committed Oct 16, 2019
1 parent dabf1c4 commit 80cc25d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
11 changes: 6 additions & 5 deletions hpat/datatypes/hpat_pandas_series_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def hpat_pandas_series_values_impl(self):


@overload_method(SeriesType, 'var')
def hapt_pandas_series_var(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None):
def hpat_pandas_series_var(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None):
"""
Pandas Series method :meth:`pandas.Series.var` implementation.
Expand All @@ -215,8 +215,8 @@ def hapt_pandas_series_var(self, axis=None, skipna=None, level=None, ddof=1, num
input series
axis: :obj:`int`, :obj:`str`
Axis along which the operation acts
0/None - row-wise operation
1 - column-wise operation
0/None/'index' - row-wise operation
1/'columns' - column-wise operation
*unsupported*
skipna: :obj:`bool`
exclude NA/null values
Expand Down Expand Up @@ -245,8 +245,9 @@ def hapt_pandas_series_var(self, axis=None, skipna=None, level=None, ddof=1, num
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))

if not isinstance(self.dtype, types.Number):
raise TypingError('{} The object must be a number. Given self.dtype: {}'.format(_func_name, self.dtype))
if not isinstance(self.data.dtype, types.Number):
msg = '{} The object must be a number. Given self.data.dtype: {}'
raise TypingError(msg.format(_func_name, self.data.dtype))

if not isinstance(skipna, (types.Omitted, types.Boolean, types.NoneType)) and skipna is not None:
raise TypingError('{} The object must be a boolean. Given skipna: {}'.format(_func_name, skipna))
Expand Down
46 changes: 36 additions & 10 deletions hpat/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@
),
]]

test_global_input_data_float64 = [
[1.0, np.nan, -1.0, 0.0, 5e-324],
[np.nan, np.inf, np.NINF, np.NZERO]
]

min_int64 = -9223372036854775808
max_int64 = 9223372036854775807
max_uint64 = 18446744073709551615

test_global_input_data_integer64 = [
[1, -1, 0, max_uint64],
[-0, min_int64, max_int64]
]

test_global_input_data_numeric = test_global_input_data_integer64 + test_global_input_data_float64

test_global_input_data_unicode_kind4 = [
'ascii',
'12345',
'1234567890',
'¡Y tú quién te crees?',
'🐍⚡',
'大处着眼,小处着手。',
]


def _make_func_from_text(func_text, func_name='test_impl'):
loc_vars = {}
Expand Down Expand Up @@ -2103,7 +2128,7 @@ def test_series_nunique_param1_impl(S, dropna):

def test_series_var(self):
def pyfunc():
series = pd.Series([1.3, -2.7, np.nan, 0.1, 10.9])
series = pd.Series([1.0, np.nan, -1.0, 0.0, 5e-324])
return series.var()

cfunc = hpat.jit(pyfunc)
Expand All @@ -2116,30 +2141,31 @@ def pyfunc(series, skipna, ddof):
return series.var(skipna=skipna, ddof=ddof)

cfunc = hpat.jit(pyfunc)
series = pd.Series([1.3, -2.7, np.nan, 0.1, 10.9])
for ddof in [0, 1]:
for skipna in [True, False]:
ref_result = pyfunc(series, skipna=skipna, ddof=ddof)
result = cfunc(series, skipna=skipna, ddof=ddof)
np.testing.assert_equal(ref_result, result)
for data in test_global_input_data_float64:
series = pd.Series(data)
for ddof in [0, 1]:
for skipna in [True, False]:
ref_result = pyfunc(series, skipna=skipna, ddof=ddof)
result = cfunc(series, skipna=skipna, ddof=ddof)
np.testing.assert_equal(ref_result, result)

def test_series_var_str(self):
def pyfunc(series):
return series.var()

cfunc = hpat.jit(pyfunc)
series = pd.Series(['test', 'series', 'var', 'str'])
series = pd.Series(test_global_input_data_unicode_kind4)
with self.assertRaises(TypingError) as raises:
cfunc(series)
msg = 'Method var(). The object must be a number. Given self.dtype: {}'
msg = 'Method var(). The object must be a number. Given self.data.dtype: {}'
self.assertIn(msg.format(types.unicode_type), str(raises.exception))

def test_series_var_unsupported_params(self):
def pyfunc(series, axis, level, numeric_only):
return series.var(axis=axis, level=level, numeric_only=numeric_only)

cfunc = hpat.jit(pyfunc)
series = pd.Series([1.3, -2.7, np.nan, 0.1, 10.9])
series = pd.Series(test_global_input_data_float64[0])
msg = 'Method var(). Unsupported parameters. Given {}: {}'
with self.assertRaises(TypingError) as raises:
cfunc(series, axis=1, level=None, numeric_only=None)
Expand Down

0 comments on commit 80cc25d

Please sign in to comment.