Browse Source

Add ut for dataset to_number

tags/v1.1.0
YangLuo 5 years ago
parent
commit
da6de519ae
4 changed files with 18 additions and 4 deletions
  1. +1
    -1
      mindspore/dataset/text/validators.py
  2. +1
    -1
      mindspore/lite/minddata/wrapper/album_op_android.cc
  3. +8
    -2
      tests/ut/cpp/dataset/c_api_text_test.cc
  4. +8
    -0
      tests/ut/python/dataset/test_to_number_op.py

+ 1
- 1
mindspore/dataset/text/validators.py View File

@@ -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)



+ 1
- 1
mindspore/lite/minddata/wrapper/album_op_android.cc View File

@@ -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;
}


+ 8
- 2
tests/ut/cpp/dataset/c_api_text_test.cc View File

@@ -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) {


+ 8
- 0
tests/ut/python/dataset/test_to_number_op.py View File

@@ -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…
Cancel
Save