From 6d25dbdfa6e6c094cedbfd7ace07e05e37025215 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 25 Mar 2020 14:07:51 +0300 Subject: [PATCH 1/3] Expand TypeChecker to raise SDCLimitation('...Unsupported...') --- sdc/utilities/sdc_typing_utils.py | 41 +++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/sdc/utilities/sdc_typing_utils.py b/sdc/utilities/sdc_typing_utils.py index 7dcb2fbfc..ee587e146 100644 --- a/sdc/utilities/sdc_typing_utils.py +++ b/sdc/utilities/sdc_typing_utils.py @@ -48,7 +48,7 @@ class TypeChecker: given: bool expected: int """ - msg_template = '{} The object {}\n given: {}\n expected: {}' + default_tmpl = '{} The object {}\n given: {}\n expected: {}' def __init__(self, func_name): """ @@ -59,9 +59,23 @@ def __init__(self, func_name): """ self.func_name = func_name - def raise_exc(self, data, expected_types, name=''): + def _raise_exc(self, exc_cls, tmpl, *args): """ - Raise exception with unified message + Generic for raising exception + Parameters + ---------- + tmpl: :obj:`any` + template for exception message + exc_cls: :obj:`Exception` + class of the exception to be raised + args: :obj:`list` + arguments to render template + """ + raise exc_cls(tmpl.format(*args)) + + def raise_exc(self, data, expected_types, name='', exc_cls=TypingError): + """ + Raise exception with message about invalid type of parameter Parameters ---------- data: :obj:`any` @@ -70,9 +84,26 @@ def raise_exc(self, data, expected_types, name=''): expected types inserting directly to the exception name: :obj:`str` name of the parameter + exc_cls: :obj:`Exception` + class of the exception to be raised + """ + self._raise_exc(self, exc_cls, self.default_tmpl, self.func_name, + name, data, expected_types) + + def raise_unsupported_exc(self, data, name='', exc_cls=TypingError): + """ + Raise exception with message about unsupported parameter + Parameters + ---------- + data: :obj:`any` + real type of the data + name: :obj:`str` + name of the parameter + exc_cls: :obj:`Exception` + class of the exception to be raised """ - msg = self.msg_template.format(self.func_name, name, data, expected_types) - raise TypingError(msg) + tmpl = '{} Unsupported object {}\n given: {}' + self._raise_exc(self, exc_cls, tmpl, self.func_name, name, data) def check(self, data, accepted_type, name=''): """ From 27eeca03e69e8d3122c45f3ef6daa3ba7cfea38f Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 25 Mar 2020 14:58:06 +0300 Subject: [PATCH 2/3] Add raising SDCLimitation by default in case of unsupported parameter --- sdc/datatypes/common_functions.py | 5 ----- sdc/datatypes/hpat_pandas_dataframe_functions.py | 2 +- sdc/tests/test_dataframe.py | 2 +- sdc/utilities/sdc_typing_utils.py | 7 ++++++- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sdc/datatypes/common_functions.py b/sdc/datatypes/common_functions.py index 508e065ef..ba533a519 100644 --- a/sdc/datatypes/common_functions.py +++ b/sdc/datatypes/common_functions.py @@ -56,11 +56,6 @@ TypeChecker) -class SDCLimitation(Exception): - """Exception to be raised in case of SDC limitation""" - pass - - def hpat_arrays_append(A, B): pass diff --git a/sdc/datatypes/hpat_pandas_dataframe_functions.py b/sdc/datatypes/hpat_pandas_dataframe_functions.py index 6240da18b..f58d88a97 100644 --- a/sdc/datatypes/hpat_pandas_dataframe_functions.py +++ b/sdc/datatypes/hpat_pandas_dataframe_functions.py @@ -54,7 +54,7 @@ from sdc.hiframes.pd_dataframe_type import DataFrameType from sdc.datatypes.hpat_pandas_dataframe_getitem_types import (DataFrameGetitemAccessorType, dataframe_getitem_accessor_init) -from sdc.datatypes.common_functions import SDCLimitation +from sdc.utilities.sdc_typing_utils import SDCLimitation from sdc.datatypes.hpat_pandas_dataframe_rolling_types import _hpat_pandas_df_rolling_init from sdc.datatypes.hpat_pandas_rolling_types import ( gen_sdc_pandas_rolling_overload_body, sdc_pandas_rolling_docstring_tmpl) diff --git a/sdc/tests/test_dataframe.py b/sdc/tests/test_dataframe.py index 232d913a4..18ab5c5e5 100644 --- a/sdc/tests/test_dataframe.py +++ b/sdc/tests/test_dataframe.py @@ -37,7 +37,7 @@ from numba.errors import TypingError import sdc -from sdc.datatypes.common_functions import SDCLimitation +from sdc.utilities.sdc_typing_utils import SDCLimitation from sdc.tests.gen_test_data import ParquetGenerator from sdc.tests.test_base import TestCase from sdc.tests.test_utils import (check_numba_version, diff --git a/sdc/utilities/sdc_typing_utils.py b/sdc/utilities/sdc_typing_utils.py index ee587e146..7a11e6e63 100644 --- a/sdc/utilities/sdc_typing_utils.py +++ b/sdc/utilities/sdc_typing_utils.py @@ -41,6 +41,11 @@ from sdc.str_arr_type import string_array_type +class SDCLimitation(Exception): + """Exception to be raised in case of SDC limitation""" + pass + + class TypeChecker: """ Validate object type and raise TypingError if the type is invalid, e.g.: @@ -90,7 +95,7 @@ class of the exception to be raised self._raise_exc(self, exc_cls, self.default_tmpl, self.func_name, name, data, expected_types) - def raise_unsupported_exc(self, data, name='', exc_cls=TypingError): + def raise_unsupported_exc(self, data, name='', exc_cls=SDCLimitation): """ Raise exception with message about unsupported parameter Parameters From aa8b017b928e31b1dd54bc3fa507f5cc252c4b31 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 25 Mar 2020 17:52:25 +0300 Subject: [PATCH 3/3] Fix private method call issue in TypeChecker --- sdc/utilities/sdc_typing_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdc/utilities/sdc_typing_utils.py b/sdc/utilities/sdc_typing_utils.py index 7a11e6e63..2b7cfff5f 100644 --- a/sdc/utilities/sdc_typing_utils.py +++ b/sdc/utilities/sdc_typing_utils.py @@ -92,7 +92,7 @@ def raise_exc(self, data, expected_types, name='', exc_cls=TypingError): exc_cls: :obj:`Exception` class of the exception to be raised """ - self._raise_exc(self, exc_cls, self.default_tmpl, self.func_name, + self._raise_exc(exc_cls, self.default_tmpl, self.func_name, name, data, expected_types) def raise_unsupported_exc(self, data, name='', exc_cls=SDCLimitation): @@ -108,7 +108,7 @@ def raise_unsupported_exc(self, data, name='', exc_cls=SDCLimitation): class of the exception to be raised """ tmpl = '{} Unsupported object {}\n given: {}' - self._raise_exc(self, exc_cls, tmpl, self.func_name, name, data) + self._raise_exc(exc_cls, tmpl, self.func_name, name, data) def check(self, data, accepted_type, name=''): """