[ 
https://issues.apache.org/jira/browse/ARROW-1491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16280622#comment-16280622
 ] 

ASF GitHub Bot commented on ARROW-1491:
---------------------------------------

wesm commented on a change in pull request #1387: ARROW-1491: [C++] Add casting 
implementations from strings to numbers or boolean
URL: https://github.com/apache/arrow/pull/1387#discussion_r155319018
 
 

 ##########
 File path: cpp/src/arrow/compute/compute-test.cc
 ##########
 @@ -769,6 +769,65 @@ TEST_F(TestCast, OffsetOutputBuffer) {
                                                                 int16(), e3);
 }
 
+TEST_F(TestCast, StringToBoolean) {
+  CastOptions options;
+
+  vector<bool> is_valid = {true, true, true, true, true};
+
+  vector<std::string> v1 = {"False", "true", "true", "True", "false"};
+  vector<std::string> v2 = {"0", "1", "1", "1", "0"};
+  vector<bool> e = {false, true, true, true, false};
+  CheckCase<StringType, std::string, BooleanType, bool>(utf8(), v1, is_valid, 
boolean(),
+                                                        e, options);
+  CheckCase<StringType, std::string, BooleanType, bool>(utf8(), v2, is_valid, 
boolean(),
+                                                        e, options);
+}
+
+TEST_F(TestCast, StringToNumber) {
+  CastOptions options;
+
+  vector<bool> is_valid = {true, true, true, true, true};
+
+  // string to int
+  vector<std::string> v_int = {"0", "1", "127", "-1", "0"};
+  vector<int8_t> e_int8 = {0, 1, 127, -1, 0};
+  vector<int16_t> e_int16 = {0, 1, 127, -1, 0};
+  vector<int32_t> e_int32 = {0, 1, 127, -1, 0};
+  vector<int64_t> e_int64 = {0, 1, 127, -1, 0};
+  CheckCase<StringType, std::string, Int8Type, int8_t>(utf8(), v_int, 
is_valid, int8(),
+                                                       e_int8, options);
+  CheckCase<StringType, std::string, Int16Type, int16_t>(utf8(), v_int, 
is_valid, int16(),
+                                                         e_int16, options);
+  CheckCase<StringType, std::string, Int32Type, int32_t>(utf8(), v_int, 
is_valid, int32(),
+                                                         e_int32, options);
+  CheckCase<StringType, std::string, Int64Type, int64_t>(utf8(), v_int, 
is_valid, int64(),
+                                                         e_int64, options);
+
+  // string to uint
+  vector<std::string> v_uint = {"0", "1", "127", "255", "0"};
+  vector<uint8_t> e_uint8 = {0, 1, 127, 255, 0};
+  vector<uint16_t> e_uint16 = {0, 1, 127, 255, 0};
+  vector<uint32_t> e_uint32 = {0, 1, 127, 255, 0};
+  vector<uint64_t> e_uint64 = {0, 1, 127, 255, 0};
+  CheckCase<StringType, std::string, UInt8Type, uint8_t>(utf8(), v_uint, 
is_valid,
+                                                         uint8(), e_uint8, 
options);
+  CheckCase<StringType, std::string, UInt16Type, uint16_t>(utf8(), v_uint, 
is_valid,
+                                                           uint16(), e_uint16, 
options);
+  CheckCase<StringType, std::string, UInt32Type, uint32_t>(utf8(), v_uint, 
is_valid,
+                                                           uint32(), e_uint32, 
options);
+  CheckCase<StringType, std::string, UInt64Type, uint64_t>(utf8(), v_uint, 
is_valid,
+                                                           uint64(), e_uint64, 
options);
+
+  // string to float
+  vector<std::string> v_float = {"0.1", "1.2", "127.3", "200.4", "0.5"};
+  vector<float> e_float = {0.1f, 1.2f, 127.3f, 200.4f, 0.5f};
+  vector<double> e_double = {0.1, 1.2, 127.3, 200.4, 0.5};
+  CheckCase<StringType, std::string, FloatType, float>(utf8(), v_float, 
is_valid,
+                                                       float32(), e_float, 
options);
+  CheckCase<StringType, std::string, DoubleType, double>(utf8(), v_float, 
is_valid,
+                                                         float64(), e_double, 
options);
 
 Review comment:
   Can you test with a non-zero offset (e.g. `foo->Slice(2)`)?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [C++] Add casting implementations from strings to numbers or boolean
> --------------------------------------------------------------------
>
>                 Key: ARROW-1491
>                 URL: https://issues.apache.org/jira/browse/ARROW-1491
>             Project: Apache Arrow
>          Issue Type: New Feature
>          Components: C++
>            Reporter: Wes McKinney
>            Assignee: Licht Takeuchi
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to