[
https://issues.apache.org/jira/browse/ARROW-1484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16219116#comment-16219116
]
ASF GitHub Bot commented on ARROW-1484:
---------------------------------------
BryanCutler commented on a change in pull request #1245: ARROW-1484:
[C++/Python] Implement casts between date, time, timestamp units
URL: https://github.com/apache/arrow/pull/1245#discussion_r146926826
##########
File path: cpp/src/arrow/compute/compute-test.cc
##########
@@ -270,6 +275,205 @@ TEST_F(TestCast, ToIntDowncastUnsafe) {
options);
}
+TEST_F(TestCast, TimestampToTimestamp) {
+ CastOptions options;
+
+ auto CheckTimestampCast = [this](
+ const CastOptions& options, TimeUnit::type from_unit, TimeUnit::type
to_unit,
+ const std::vector<int64_t>& from_values, const std::vector<int64_t>&
to_values,
+ const std::vector<bool>& is_valid) {
+ CheckCase<TimestampType, int64_t, TimestampType, int64_t>(
+ timestamp(from_unit), from_values, is_valid, timestamp(to_unit),
to_values,
+ options);
+ };
+
+ vector<bool> is_valid = {true, false, true, true, true};
+
+ // Multiply promotions
+ vector<int64_t> v1 = {0, 100, 200, 1, 2};
+ vector<int64_t> e1 = {0, 100000, 200000, 1000, 2000};
+ CheckTimestampCast(options, TimeUnit::SECOND, TimeUnit::MILLI, v1, e1,
is_valid);
+
+ vector<int64_t> v2 = {0, 100, 200, 1, 2};
+ vector<int64_t> e2 = {0, 100000000L, 200000000L, 1000000, 2000000};
+ CheckTimestampCast(options, TimeUnit::SECOND, TimeUnit::MICRO, v2, e2,
is_valid);
+
+ vector<int64_t> v3 = {0, 100, 200, 1, 2};
+ vector<int64_t> e3 = {0, 100000000000L, 200000000000L, 1000000000L,
2000000000L};
+ CheckTimestampCast(options, TimeUnit::SECOND, TimeUnit::NANO, v3, e3,
is_valid);
+
+ vector<int64_t> v4 = {0, 100, 200, 1, 2};
+ vector<int64_t> e4 = {0, 100000, 200000, 1000, 2000};
+ CheckTimestampCast(options, TimeUnit::MILLI, TimeUnit::MICRO, v4, e4,
is_valid);
+
+ vector<int64_t> v5 = {0, 100, 200, 1, 2};
+ vector<int64_t> e5 = {0, 100000000L, 200000000L, 1000000, 2000000};
+ CheckTimestampCast(options, TimeUnit::MILLI, TimeUnit::NANO, v5, e5,
is_valid);
+
+ vector<int64_t> v6 = {0, 100, 200, 1, 2};
+ vector<int64_t> e6 = {0, 100000, 200000, 1000, 2000};
+ CheckTimestampCast(options, TimeUnit::MICRO, TimeUnit::NANO, v6, e6,
is_valid);
+
+ // Zero copy
+ std::shared_ptr<Array> arr;
+ vector<int64_t> v7 = {0, 70000, 2000, 1000, 0};
+ ArrayFromVector<TimestampType, int64_t>(timestamp(TimeUnit::SECOND),
is_valid, v7,
+ &arr);
+ CheckZeroCopy(*arr, timestamp(TimeUnit::SECOND));
+
+ // Divide, truncate
+ vector<int64_t> v8 = {0, 100123, 200456, 1123, 2456};
+ vector<int64_t> e8 = {0, 100, 200, 1, 2};
+
+ options.allow_time_truncate = true;
Review comment:
Does this option need to be set in pyarrow to prevent an error when
truncating?
----------------------------------------------------------------
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:
[email protected]
> [C++] Implement (safe and unsafe) casts between timestamps and times of
> different units
> ---------------------------------------------------------------------------------------
>
> Key: ARROW-1484
> URL: https://issues.apache.org/jira/browse/ARROW-1484
> Project: Apache Arrow
> Issue Type: New Feature
> Components: C++
> Reporter: Wes McKinney
> Assignee: Wes McKinney
> Labels: pull-request-available
> Fix For: 0.8.0
>
>
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)