MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_date_impl

Function test_date_impl

arrow-arith/src/numeric.rs:1529–1616  ·  view source on GitHub ↗
(f: F)

Source from the content-addressed store, hash-verified

1527 }
1528
1529 fn test_date_impl<T: ArrowPrimitiveType, F>(f: F)
1530 where
1531 F: Fn(NaiveDate) -> T::Native,
1532 T::Native: TryInto<i64>,
1533 {
1534 let a = PrimitiveArray::<T>::new(
1535 vec![
1536 f(NaiveDate::from_ymd_opt(1979, 1, 30).unwrap()),
1537 f(NaiveDate::from_ymd_opt(2010, 4, 3).unwrap()),
1538 f(NaiveDate::from_ymd_opt(2008, 2, 29).unwrap()),
1539 ]
1540 .into(),
1541 None,
1542 );
1543
1544 let b = IntervalYearMonthArray::from(vec![
1545 IntervalYearMonthType::make_value(34, 2),
1546 IntervalYearMonthType::make_value(3, -3),
1547 IntervalYearMonthType::make_value(-12, 4),
1548 ]);
1549
1550 let format_array = |x: &dyn Array| -> Vec<String> {
1551 x.as_primitive::<T>()
1552 .values()
1553 .into_iter()
1554 .map(|x| {
1555 as_date::<T>((*x).try_into().ok().unwrap())
1556 .unwrap()
1557 .to_string()
1558 })
1559 .collect()
1560 };
1561
1562 let result = add(&a, &b).unwrap();
1563 assert_eq!(
1564 &format_array(result.as_ref()),
1565 &[
1566 "2013-03-30".to_string(),
1567 "2013-01-03".to_string(),
1568 "1996-06-29".to_string(),
1569 ]
1570 );
1571 let result = sub(&result, &b).unwrap();
1572 assert_eq!(result.as_ref(), &a);
1573
1574 let b = IntervalDayTimeArray::from(vec![
1575 IntervalDayTimeType::make_value(34, 2),
1576 IntervalDayTimeType::make_value(3, -3),
1577 IntervalDayTimeType::make_value(-12, 4),
1578 ]);
1579
1580 let result = add(&a, &b).unwrap();
1581 assert_eq!(
1582 &format_array(result.as_ref()),
1583 &[
1584 "1979-03-05".to_string(),
1585 "2010-04-06".to_string(),
1586 "2008-02-17".to_string(),

Callers

nothing calls this directly

Calls 5

addFunction · 0.85
subFunction · 0.85
collectMethod · 0.80
into_iterMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected