Minor error message improvement for incompatible type conversion.
PiperOrigin-RevId: 222282332
This commit is contained in:
parent
bf8544fccf
commit
a8ae0f47e5
@ -439,8 +439,8 @@ int EagerTensor_init(EagerTensor* self, PyObject* args, PyObject* kwds) {
|
|||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
PyExc_TypeError,
|
PyExc_TypeError,
|
||||||
tensorflow::strings::StrCat(
|
tensorflow::strings::StrCat(
|
||||||
"Cannot convert value ", TFE_GetPythonString(value_str.get()),
|
"Cannot convert provided value to EagerTensor. Provided value: ",
|
||||||
" to EagerTensor with requested dtype: ",
|
TFE_GetPythonString(value_str.get()), " Requested dtype: ",
|
||||||
tensorflow::DataTypeString(
|
tensorflow::DataTypeString(
|
||||||
static_cast<tensorflow::DataType>(desired_dtype)))
|
static_cast<tensorflow::DataType>(desired_dtype)))
|
||||||
.c_str());
|
.c_str());
|
||||||
|
@ -2303,8 +2303,10 @@ bool ConvertToTensor(
|
|||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
PyExc_TypeError,
|
PyExc_TypeError,
|
||||||
tensorflow::strings::StrCat(
|
tensorflow::strings::StrCat(
|
||||||
"Cannot convert value ", TFE_GetPythonString(input_str.get()),
|
"Cannot convert provided value to EagerTensor. Provided value: ",
|
||||||
" to EagerTensor with requested dtype: ", desired_dtype)
|
TFE_GetPythonString(input_str.get()), " Requested dtype: ",
|
||||||
|
tensorflow::DataTypeString(
|
||||||
|
static_cast<tensorflow::DataType>(desired_dtype)))
|
||||||
.c_str());
|
.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -323,6 +323,14 @@ class TFETensorTest(test_util.TensorFlowTestCase):
|
|||||||
def testConvertToTensorAllowsOverflow(self):
|
def testConvertToTensorAllowsOverflow(self):
|
||||||
_ = ops.convert_to_tensor(123456789, dtype=dtypes.uint8)
|
_ = 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):
|
class TFETensorUtilTest(test_util.TensorFlowTestCase):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user