diff --git a/hpat/hiframes/hiframes_typed.py b/hpat/hiframes/hiframes_typed.py index 7fed68f7c..30fdae207 100644 --- a/hpat/hiframes/hiframes_typed.py +++ b/hpat/hiframes/hiframes_typed.py @@ -1011,8 +1011,8 @@ def func(A, B): return hpat.hiframes.api.init_series( data = self._get_series_data(series_var, nodes) return self._replace_func(func, [data], pre_nodes=nodes) - if func_name in explicit_binop_funcs.values(): - binop_map = {v: _binop_to_str[k] for k, v in explicit_binop_funcs.items()} + if func_name in explicit_binop_funcs.keys(): + binop_map = {k: _binop_to_str[v] for k, v in explicit_binop_funcs.items()} func_text = "def _binop_impl(A, B):\n" func_text += " return A {} B\n".format(binop_map[func_name]) diff --git a/hpat/hiframes/pd_series_ext.py b/hpat/hiframes/pd_series_ext.py index f400bf9fd..79061ccda 100644 --- a/hpat/hiframes/pd_series_ext.py +++ b/hpat/hiframes/pd_series_ext.py @@ -974,28 +974,27 @@ def array_attribute_attachment(self, ary): explicit_binop_funcs = { - operator.add: 'add', - operator.sub: 'sub', - operator.mul: 'mul', - operator.truediv: 'div', - operator.truediv: 'truediv', - operator.floordiv: 'floordiv', - operator.mod: 'mod', - operator.pow: 'pow', - operator.lt: 'lt', - operator.gt: 'gt', - operator.le: 'le', - operator.ge: 'ge', - operator.ne: 'ne', - operator.eq: 'eq', + 'add': operator.add, + 'sub': operator.sub, + 'mul': operator.mul, + 'div': operator.truediv, + 'truediv': operator.truediv, + 'floordiv': operator.floordiv, + 'mod': operator.mod, + 'pow': operator.pow, + 'lt': operator.lt, + 'gt': operator.gt, + 'le': operator.le, + 'ge': operator.ge, + 'ne': operator.ne, + 'eq': operator.eq, } def ex_binop_generic(self, args, kws): return SeriesOpUfuncs.generic(self, (self.this,) + args, kws) - -for op, fname in explicit_binop_funcs.items(): +for fname, op in explicit_binop_funcs.items(): install_series_method(op, fname, ex_binop_generic) diff --git a/hpat/tests/test_series.py b/hpat/tests/test_series.py index 660a5b49b..d4f46369d 100644 --- a/hpat/tests/test_series.py +++ b/hpat/tests/test_series.py @@ -417,52 +417,69 @@ def test_impl(A): hpat_func(S), test_impl(S).reset_index(drop=True)) def test_series_op1(self): - def test_impl(A, i): - return A + A - hpat_func = hpat.jit(test_impl) + arithmetic_binops = ('+', '-', '*', '/', '//', '%', '**') - n = 11 - df = pd.DataFrame({'A': np.arange(n)}) - pd.testing.assert_series_equal(hpat_func(df.A, 0), - test_impl(df.A, 0), check_names=False) + for operator in arithmetic_binops: + func_text = "def test_impl(S):\n" + func_text += " return S {} S\n".format(operator) + loc_vars = {} + exec(func_text, {}, loc_vars) + test_impl = loc_vars['test_impl'] + hpat_func = hpat.jit(test_impl) + + n = 11 + df = pd.DataFrame({'A': np.arange(1, n)}) + pd.testing.assert_series_equal(hpat_func(df.A), test_impl(df.A), check_names=False) - @unittest.skip('AssertionError - fix needed\n' - 'Attribute "dtype" are different\n' - '[left]: int64\n' - '[right]: int32\n') def test_series_op2(self): - def test_impl(A, i): - return A+i - hpat_func = hpat.jit(test_impl) + arithmetic_binops = ('+', '-', '*', '/', '//', '%', '**') - n = 11 - df = pd.DataFrame({'A': np.arange(n)}) - pd.testing.assert_series_equal(hpat_func(df.A, 1), - test_impl(df.A, 1), check_names=False) + for operator in arithmetic_binops: + func_text = "def test_impl(S, i):\n" + func_text += " return S {} i\n".format(operator) + loc_vars = {} + exec(func_text, {}, loc_vars) + test_impl = loc_vars['test_impl'] + hpat_func = hpat.jit(test_impl) + + n = 11 + df = pd.DataFrame({'A': np.arange(1, n)}) + pd.testing.assert_series_equal(hpat_func(df.A, 1), test_impl(df.A, 1), check_names=False) def test_series_op3(self): - def test_impl(A, i): - A += i - return A - hpat_func = hpat.jit(test_impl) + arithmetic_binops = ('+', '-', '*', '/', '//', '%', '**') - n = 11 - df = pd.DataFrame({'A': np.arange(n)}) - pd.testing.assert_series_equal(hpat_func(df.A.copy(), 1), - test_impl(df.A, 1), check_names=False) + for operator in arithmetic_binops: + func_text = "def test_impl(S, i):\n" + func_text += " S {} i\n".format(operator) + func_text += " return S\n" + loc_vars = {} + exec(func_text, {}, loc_vars) + test_impl = loc_vars['test_impl'] + hpat_func = hpat.jit(test_impl) + + n = 11 + df = pd.DataFrame({'A': np.arange(1, n)}) + pd.testing.assert_series_equal(hpat_func(df.A, 1), test_impl(df.A, 1), check_names=False) def test_series_op4(self): - def test_impl(A): - return A.add(A) - hpat_func = hpat.jit(test_impl) + arithmetic_methods = ('add', 'sub', 'mul', 'div', 'truediv', 'floordiv', 'mod', 'pow') - n = 11 - A = pd.Series(np.arange(n)) - pd.testing.assert_series_equal(hpat_func(A), test_impl(A)) + for method in arithmetic_methods: + func_text = "def test_impl(S):\n" + func_text += " return S.{}(S)\n".format(method) + loc_vars = {} + exec(func_text, {}, loc_vars) + test_impl = loc_vars['test_impl'] + hpat_func = hpat.jit(test_impl) + + n = 11 + df = pd.DataFrame({'A': np.arange(1, n)}) + pd.testing.assert_series_equal(hpat_func(df.A), test_impl(df.A), check_names=False) def test_series_op5(self): def test_impl(A): - return A.pow(A) + return -A hpat_func = hpat.jit(test_impl) n = 11 @@ -470,23 +487,36 @@ def test_impl(A): pd.testing.assert_series_equal(hpat_func(A), test_impl(A)) def test_series_op6(self): - def test_impl(A, B): - return A.eq(B) - hpat_func = hpat.jit(test_impl) - - n = 11 - A = pd.Series(np.arange(n)) - B = pd.Series(np.arange(n)**2) - pd.testing.assert_series_equal(hpat_func(A, B), test_impl(A, B)) + comparison_binops = ('<', '>', '<=', '>=', '!=', '==') + for operator in comparison_binops: + func_text = "def test_impl(A, B):\n" + func_text += " return A {} B\n".format(operator) + loc_vars = {} + exec(func_text, {}, loc_vars) + test_impl = loc_vars['test_impl'] + hpat_func = hpat.jit(test_impl) + + n = 11 + A = pd.Series(np.arange(n)) + B = pd.Series(np.arange(n)**2) + pd.testing.assert_series_equal(hpat_func(A, B), test_impl(A, B), check_names=False) + def test_series_op7(self): - def test_impl(A): - return -A - hpat_func = hpat.jit(test_impl) + comparison_methods = ('lt', 'gt', 'le', 'ge', 'ne', 'eq') - n = 11 - A = pd.Series(np.arange(n)) - pd.testing.assert_series_equal(hpat_func(A), test_impl(A)) + for method in comparison_methods: + func_text = "def test_impl(A, B):\n" + func_text += " return A.{}(B)\n".format(method) + loc_vars = {} + exec(func_text, {}, loc_vars) + test_impl = loc_vars['test_impl'] + hpat_func = hpat.jit(test_impl) + + n = 11 + A = pd.Series(np.arange(n)) + B = pd.Series(np.arange(n)**2) + pd.testing.assert_series_equal(hpat_func(A, B), test_impl(A, B), check_names=False) def test_series_inplace_binop_array(self): def test_impl(A, B): @@ -499,10 +529,15 @@ def test_impl(A, B): B = pd.Series(np.ones(n)) np.testing.assert_array_equal(hpat_func(A.copy(), B), test_impl(A, B)) - @unittest.skip('AssertionError - fix needed\n' - 'Attribute "dtype" are different\n' - '[left]: int64\n' - '[right]: int32\n') + def test_series_abs(self): + def test_impl(A): + return A.abs() + hpat_func = hpat.jit(test_impl) + + S = pd.Series([1, 2.2, -5.8, 3, 2, -1.2, -4, 4.7]) + pd.testing.assert_series_equal(hpat_func(S), test_impl(S)) + + def test_series_fusion1(self): def test_impl(A, B): return A + B + 1 @@ -514,10 +549,6 @@ def test_impl(A, B): pd.testing.assert_series_equal(hpat_func(A, B), test_impl(A, B)) self.assertEqual(count_parfor_REPs(), 1) - @unittest.skip('AssertionError - fix needed\n' - 'Attribute "dtype" are different\n' - '[left]: int64\n' - '[right]: int32\n') def test_series_fusion2(self): # make sure getting data var avoids incorrect single def assumption def test_impl(A, B): @@ -1059,11 +1090,6 @@ def test_impl(S): S = pd.Series(['aa', 'abc', 'c', 'cccd']) pd.testing.assert_series_equal(hpat_func(S), test_impl(S)) - @unittest.skip('numba.errors.LoweringError - fix needed\n' - 'Failed in hpat mode pipeline' - '(step: nopython mode backend)\n' - 'str_overload() takes 1 positional argument ' - 'but 2 were given\n') def test_series_str2str(self): str2str_methods = ('capitalize', 'lower', 'lstrip', 'rstrip', 'strip', 'swapcase', 'title', 'upper')