Minor error message improvement for incompatible type conversion.

PiperOrigin-RevId: 222282332
This commit is contained in:
Akshay Modi 2018-11-20 11:52:19 -08:00 committed by TensorFlower Gardener
parent bf8544fccf
commit a8ae0f47e5
3 changed files with 14 additions and 4 deletions

View File

@ -439,8 +439,8 @@ int EagerTensor_init(EagerTensor* self, PyObject* args, PyObject* kwds) {
PyErr_SetString(
PyExc_TypeError,
tensorflow::strings::StrCat(
"Cannot convert value ", TFE_GetPythonString(value_str.get()),
" to EagerTensor with requested dtype: ",
"Cannot convert provided value to EagerTensor. Provided value: ",
TFE_GetPythonString(value_str.get()), " Requested dtype: ",
tensorflow::DataTypeString(
static_cast<tensorflow::DataType>(desired_dtype)))
.c_str());

View File

@ -2303,8 +2303,10 @@ bool ConvertToTensor(
PyErr_SetString(
PyExc_TypeError,
tensorflow::strings::StrCat(
"Cannot convert value ", TFE_GetPythonString(input_str.get()),
" to EagerTensor with requested dtype: ", desired_dtype)
"Cannot convert provided value to EagerTensor. Provided value: ",
TFE_GetPythonString(input_str.get()), " Requested dtype: ",
tensorflow::DataTypeString(
static_cast<tensorflow::DataType>(desired_dtype)))
.c_str());
return false;
}

View File

@ -323,6 +323,14 @@ class TFETensorTest(test_util.TensorFlowTestCase):
def testConvertToTensorAllowsOverflow(self):
_ = ops.convert_to_tensor(123456789, dtype=dtypes.uint8)
def testEagerTensorError(self):
with self.assertRaisesRegexp(
TypeError,
"Cannot convert provided value to EagerTensor. "
"Provided value.*Requested dtype.*"):
_ = ops.convert_to_tensor(1., dtype=dtypes.int32)
class TFETensorUtilTest(test_util.TensorFlowTestCase):