forked from mindspore-Ecosystem/mindspore
!10287 Add ut for dataset to_number
From: @luoyang42 Reviewed-by: @heleiwang Signed-off-by:
This commit is contained in:
commit
20df37e428
|
@ -402,7 +402,7 @@ def check_to_number(method):
|
|||
type_check(data_type, (typing.Type,), "data_type")
|
||||
|
||||
if data_type not in mstype.number_type:
|
||||
raise TypeError("data_type is not numeric data type.")
|
||||
raise TypeError("data_type: " + str(data_type) + " is not numeric data type.")
|
||||
|
||||
return method(self, *args, **kwargs)
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ Status AlbumOp::LoadImageTensor(const std::string &image_file_path, uint32_t col
|
|||
// get orientation from EXIF file
|
||||
int AlbumOp::GetOrientation(const std::string &folder_path) {
|
||||
FILE *fp = fopen(folder_path.c_str(), "rb");
|
||||
if (!fp) {
|
||||
if (fp == nullptr) {
|
||||
MS_LOG(ERROR) << "Can't read file for EXIF: file = " << folder_path;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1255,10 +1255,16 @@ TEST_F(MindDataTestPipeline, TestToNumberFail4) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create ToNumber operation on ds
|
||||
std::shared_ptr<TensorOperation> to_number = text::ToNumber(DataType("string"));
|
||||
std::shared_ptr<TensorOperation> to_number1 = text::ToNumber(DataType("string"));
|
||||
|
||||
// Expect failure: invalid parameter with non numerical DataType
|
||||
EXPECT_EQ(to_number, nullptr);
|
||||
EXPECT_EQ(to_number1, nullptr);
|
||||
|
||||
// Create ToNumber operation on ds
|
||||
std::shared_ptr<TensorOperation> to_number2 = text::ToNumber(DataType("bool"));
|
||||
|
||||
// Expect failure: invalid parameter with non numerical DataType
|
||||
EXPECT_EQ(to_number2, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestTruncateSequencePairSuccess1) {
|
||||
|
|
|
@ -186,6 +186,13 @@ def test_to_number_invalid_input():
|
|||
assert "It is invalid to convert " + input_strings[0] + " to a number" in str(info.value)
|
||||
|
||||
|
||||
def test_to_number_invalid_type():
|
||||
with pytest.raises(TypeError) as info:
|
||||
dataset = ds.GeneratorDataset(string_dataset_generator(["a8fa9ds8fa"]), "strings")
|
||||
dataset = dataset.map(operations=text.ToNumber(mstype.bool_), input_columns=["strings"])
|
||||
assert "data_type: Bool is not numeric data type" in str(info.value)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_to_number_typical_case_integral()
|
||||
test_to_number_typical_case_non_integral()
|
||||
|
@ -193,3 +200,4 @@ if __name__ == '__main__':
|
|||
test_to_number_out_of_bounds_integral()
|
||||
test_to_number_out_of_bounds_non_integral()
|
||||
test_to_number_invalid_input()
|
||||
test_to_number_invalid_type()
|
||||
|
|
Loading…
Reference in New Issue