Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PyOV] Format the type in "Unidentified data type" errors (#39047)

Dakshaec27878c86f0
diff --git a/src/bindings/python/src/openvino/utils/types.py b/src/bindings/python/src/openvino/utils/types.py
index 2e78f8a0270..4f0b02761d1 100644
--- a/src/bindings/python/src/openvino/utils/types.py
+++ b/src/bindings/python/src/openvino/utils/types.py
@@ -80,7 +80,7 @@ def get_element_type(data_type: NumericType) -> Type:
if ov_type:
return ov_type
- raise OVTypeError("Unidentified data type %s", data_type)
+ raise OVTypeError(f"Unidentified data type {data_type}")
def get_element_type_str(data_type: NumericType) -> str:
@@ -100,7 +100,7 @@ def get_element_type_str(data_type: NumericType) -> str:
if ov_type:
return ov_type
- raise OVTypeError("Unidentified data type %s", data_type)
+ raise OVTypeError(f"Unidentified data type {data_type}")
def get_dtype(openvino_type: Type) -> np.dtype:
@@ -113,7 +113,7 @@ def get_dtype(openvino_type: Type) -> np.dtype:
if np_type:
return np.dtype(np_type)
- raise OVTypeError("Unidentified data type %s", openvino_type)
+ raise OVTypeError(f"Unidentified data type {openvino_type}")
def get_numpy_ctype(openvino_type: Type) -> type:
@@ -126,7 +126,7 @@ def get_numpy_ctype(openvino_type: Type) -> type:
if np_type:
return np_type
- raise OVTypeError("Unidentified data type %s", openvino_type)
+ raise OVTypeError(f"Unidentified data type {openvino_type}")
def get_ndarray(data: NumericData) -> np.ndarray:
diff --git a/src/bindings/python/tests/test_utils/test_utils.py b/src/bindings/python/tests/test_utils/test_utils.py
index b0f788a5d7d..5e479c97663 100644
--- a/src/bindings/python/tests/test_utils/test_utils.py
+++ b/src/bindings/python/tests/test_utils/test_utils.py
@@ -8,6 +8,8 @@ import numpy as np
import openvino as ov
from pathlib import Path
from openvino.utils import deprecated, get_cmake_path, make_postponed_constant
+from openvino.exceptions import OVTypeError
+from openvino.utils.types import get_element_type, get_element_type_str, get_dtype, get_numpy_ctype
from tests.utils.helpers import compare_models, get_relu_model, create_filenames_for_ir
@@ -194,3 +196,15 @@ def test_infer_postponned_constant():
expected_output = np.array([4, 5, 6, 7], dtype=np.float32).reshape(1, 2, 1, 2)
assert np.allclose(results[list(results)[0]], expected_output, 1e-4, 1e-4)
+
+
[email protected](("func", "data_type"), [
+ (get_element_type, np.complex64),
+ (get_element_type_str, np.complex64),
+ (get_dtype, ov.Type.i4),
+ (get_numpy_ctype, ov.Type.i4),
+])
+def test_unidentified_type_error_message(func, data_type):
+ with pytest.raises(OVTypeError) as e:
+ func(data_type)
+ assert str(e.value) == f"Unidentified data type {data_type}"