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 b78d0ec82..80df4fc4c 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 7dcb2fbfc..2b7cfff5f 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.: @@ -48,7 +53,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 +64,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): + """ + 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 unified message + Raise exception with message about invalid type of parameter Parameters ---------- data: :obj:`any` @@ -70,9 +89,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(exc_cls, self.default_tmpl, self.func_name, + name, data, expected_types) + + def raise_unsupported_exc(self, data, name='', exc_cls=SDCLimitation): + """ + 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(exc_cls, tmpl, self.func_name, name, data) def check(self, data, accepted_type, name=''): """