alamb commented on code in PR #2251:
URL: https://github.com/apache/arrow-rs/pull/2251#discussion_r935500422
##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -2854,6 +3172,102 @@ mod tests {
}
}
+ #[test]
+ fn test_cast_string_to_time32second() {
+ let a1 = Arc::new(StringArray::from(vec![
+ Some("08:08:35.091323414"),
+ Some("08:08:60.091323414"), // leap second
+ Some("08:08:61.091323414"), // not valid
+ Some("Not a valid time"),
+ None,
+ ])) as ArrayRef;
+ let a2 = Arc::new(LargeStringArray::from(vec![
+ Some("08:08:35.091323414"),
+ Some("08:08:60.091323414"), // leap second
+ Some("08:08:61.091323414"), // not valid
+ Some("Not a valid time"),
+ None,
+ ])) as ArrayRef;
+ for array in &[a1, a2] {
+ let b = cast(array, &DataType::Time32(TimeUnit::Second)).unwrap();
+ let c = b.as_any().downcast_ref::<Time32SecondArray>().unwrap();
+ assert_eq!(29315, c.value(0));
+ assert_eq!(29340, c.value(1));
+ assert!(c.is_null(2));
+ assert!(c.is_null(3));
+ assert!(c.is_null(4));
+ }
+ }
+
+ #[test]
+ fn test_cast_string_to_time32millisecond() {
+ let a1 = Arc::new(StringArray::from(vec![
+ Some("08:08:35.091323414"),
+ Some("08:08:60.091323414"), // leap second
+ Some("08:08:61.091323414"), // not valid
+ Some("Not a valid time"),
+ None,
+ ])) as ArrayRef;
+ let a2 = Arc::new(LargeStringArray::from(vec![
+ Some("08:08:35.091323414"),
+ Some("08:08:60.091323414"), // leap second
+ Some("08:08:61.091323414"), // not valid
+ Some("Not a valid time"),
+ None,
+ ])) as ArrayRef;
+ for array in &[a1, a2] {
+ let b = cast(array,
&DataType::Time32(TimeUnit::Millisecond)).unwrap();
+ let c =
b.as_any().downcast_ref::<Time32MillisecondArray>().unwrap();
+ assert_eq!(29315091, c.value(0));
+ assert_eq!(29340091, c.value(1));
+ assert!(c.is_null(2));
+ assert!(c.is_null(3));
+ assert!(c.is_null(4));
+ }
Review Comment:
I didn't see any tests for the fallable path (aka that throws an error). I
want to have another crack at using the iterators so I'll add those tests in a
follow up
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]