You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/11/13 05:48:55 UTC

[arrow-rs] branch master updated: Fix clippy by avoiding deprecated functions in chrono (#3096)

This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new ccc44170a Fix clippy by avoiding deprecated functions in chrono (#3096)
ccc44170a is described below

commit ccc44170acadf1efb01b3a536ad48ae03328b3f1
Author: Liang-Chi Hsieh <vi...@gmail.com>
AuthorDate: Sat Nov 12 21:48:50 2022 -0800

    Fix clippy by avoiding deprecated functions in chrono (#3096)
    
    * Fix clippy
    
    * Fix test
    
    * Trigger Build
---
 arrow-array/src/delta.rs                | 207 ++++++++++++++++++++++++--------
 arrow-array/src/temporal_conversions.rs |   2 +-
 arrow-array/src/timezone.rs             |  34 ++++--
 arrow-array/src/types.rs                |   8 +-
 arrow-cast/src/cast.rs                  |  16 ++-
 arrow-cast/src/parse.rs                 |  16 +--
 arrow-csv/src/reader.rs                 |  24 ++--
 arrow/benches/cast_kernels.rs           |   6 +-
 arrow/src/compute/kernels/arithmetic.rs |  24 ++--
 parquet/src/record/api.rs               |  21 +++-
 10 files changed, 248 insertions(+), 110 deletions(-)

diff --git a/arrow-array/src/delta.rs b/arrow-array/src/delta.rs
index b7efdab0a..b9b7a11e2 100644
--- a/arrow-array/src/delta.rs
+++ b/arrow-array/src/delta.rs
@@ -105,75 +105,186 @@ mod tests {
 
     #[test]
     fn test_shift_months() {
-        let base = NaiveDate::from_ymd(2020, 1, 31);
-
-        assert_eq!(shift_months(base, 0), NaiveDate::from_ymd(2020, 1, 31));
-        assert_eq!(shift_months(base, 1), NaiveDate::from_ymd(2020, 2, 29));
-        assert_eq!(shift_months(base, 2), NaiveDate::from_ymd(2020, 3, 31));
-        assert_eq!(shift_months(base, 3), NaiveDate::from_ymd(2020, 4, 30));
-        assert_eq!(shift_months(base, 4), NaiveDate::from_ymd(2020, 5, 31));
-        assert_eq!(shift_months(base, 5), NaiveDate::from_ymd(2020, 6, 30));
-        assert_eq!(shift_months(base, 6), NaiveDate::from_ymd(2020, 7, 31));
-        assert_eq!(shift_months(base, 7), NaiveDate::from_ymd(2020, 8, 31));
-        assert_eq!(shift_months(base, 8), NaiveDate::from_ymd(2020, 9, 30));
-        assert_eq!(shift_months(base, 9), NaiveDate::from_ymd(2020, 10, 31));
-        assert_eq!(shift_months(base, 10), NaiveDate::from_ymd(2020, 11, 30));
-        assert_eq!(shift_months(base, 11), NaiveDate::from_ymd(2020, 12, 31));
-        assert_eq!(shift_months(base, 12), NaiveDate::from_ymd(2021, 1, 31));
-        assert_eq!(shift_months(base, 13), NaiveDate::from_ymd(2021, 2, 28));
-
-        assert_eq!(shift_months(base, -1), NaiveDate::from_ymd(2019, 12, 31));
-        assert_eq!(shift_months(base, -2), NaiveDate::from_ymd(2019, 11, 30));
-        assert_eq!(shift_months(base, -3), NaiveDate::from_ymd(2019, 10, 31));
-        assert_eq!(shift_months(base, -4), NaiveDate::from_ymd(2019, 9, 30));
-        assert_eq!(shift_months(base, -5), NaiveDate::from_ymd(2019, 8, 31));
-        assert_eq!(shift_months(base, -6), NaiveDate::from_ymd(2019, 7, 31));
-        assert_eq!(shift_months(base, -7), NaiveDate::from_ymd(2019, 6, 30));
-        assert_eq!(shift_months(base, -8), NaiveDate::from_ymd(2019, 5, 31));
-        assert_eq!(shift_months(base, -9), NaiveDate::from_ymd(2019, 4, 30));
-        assert_eq!(shift_months(base, -10), NaiveDate::from_ymd(2019, 3, 31));
-        assert_eq!(shift_months(base, -11), NaiveDate::from_ymd(2019, 2, 28));
-        assert_eq!(shift_months(base, -12), NaiveDate::from_ymd(2019, 1, 31));
-        assert_eq!(shift_months(base, -13), NaiveDate::from_ymd(2018, 12, 31));
-
-        assert_eq!(shift_months(base, 1265), NaiveDate::from_ymd(2125, 6, 30));
+        let base = NaiveDate::from_ymd_opt(2020, 1, 31).unwrap();
+
+        assert_eq!(
+            shift_months(base, 0),
+            NaiveDate::from_ymd_opt(2020, 1, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 1),
+            NaiveDate::from_ymd_opt(2020, 2, 29).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 2),
+            NaiveDate::from_ymd_opt(2020, 3, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 3),
+            NaiveDate::from_ymd_opt(2020, 4, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 4),
+            NaiveDate::from_ymd_opt(2020, 5, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 5),
+            NaiveDate::from_ymd_opt(2020, 6, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 6),
+            NaiveDate::from_ymd_opt(2020, 7, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 7),
+            NaiveDate::from_ymd_opt(2020, 8, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 8),
+            NaiveDate::from_ymd_opt(2020, 9, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 9),
+            NaiveDate::from_ymd_opt(2020, 10, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 10),
+            NaiveDate::from_ymd_opt(2020, 11, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 11),
+            NaiveDate::from_ymd_opt(2020, 12, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 12),
+            NaiveDate::from_ymd_opt(2021, 1, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 13),
+            NaiveDate::from_ymd_opt(2021, 2, 28).unwrap()
+        );
+
+        assert_eq!(
+            shift_months(base, -1),
+            NaiveDate::from_ymd_opt(2019, 12, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -2),
+            NaiveDate::from_ymd_opt(2019, 11, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -3),
+            NaiveDate::from_ymd_opt(2019, 10, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -4),
+            NaiveDate::from_ymd_opt(2019, 9, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -5),
+            NaiveDate::from_ymd_opt(2019, 8, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -6),
+            NaiveDate::from_ymd_opt(2019, 7, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -7),
+            NaiveDate::from_ymd_opt(2019, 6, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -8),
+            NaiveDate::from_ymd_opt(2019, 5, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -9),
+            NaiveDate::from_ymd_opt(2019, 4, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -10),
+            NaiveDate::from_ymd_opt(2019, 3, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -11),
+            NaiveDate::from_ymd_opt(2019, 2, 28).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -12),
+            NaiveDate::from_ymd_opt(2019, 1, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -13),
+            NaiveDate::from_ymd_opt(2018, 12, 31).unwrap()
+        );
+
+        assert_eq!(
+            shift_months(base, 1265),
+            NaiveDate::from_ymd_opt(2125, 6, 30).unwrap()
+        );
     }
 
     #[test]
     fn test_shift_months_with_overflow() {
-        let base = NaiveDate::from_ymd(2020, 12, 31);
+        let base = NaiveDate::from_ymd_opt(2020, 12, 31).unwrap();
 
         assert_eq!(shift_months(base, 0), base);
-        assert_eq!(shift_months(base, 1), NaiveDate::from_ymd(2021, 1, 31));
-        assert_eq!(shift_months(base, 2), NaiveDate::from_ymd(2021, 2, 28));
-        assert_eq!(shift_months(base, 12), NaiveDate::from_ymd(2021, 12, 31));
-        assert_eq!(shift_months(base, 18), NaiveDate::from_ymd(2022, 6, 30));
-
-        assert_eq!(shift_months(base, -1), NaiveDate::from_ymd(2020, 11, 30));
-        assert_eq!(shift_months(base, -2), NaiveDate::from_ymd(2020, 10, 31));
-        assert_eq!(shift_months(base, -10), NaiveDate::from_ymd(2020, 2, 29));
-        assert_eq!(shift_months(base, -12), NaiveDate::from_ymd(2019, 12, 31));
-        assert_eq!(shift_months(base, -18), NaiveDate::from_ymd(2019, 6, 30));
+        assert_eq!(
+            shift_months(base, 1),
+            NaiveDate::from_ymd_opt(2021, 1, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 2),
+            NaiveDate::from_ymd_opt(2021, 2, 28).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 12),
+            NaiveDate::from_ymd_opt(2021, 12, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, 18),
+            NaiveDate::from_ymd_opt(2022, 6, 30).unwrap()
+        );
+
+        assert_eq!(
+            shift_months(base, -1),
+            NaiveDate::from_ymd_opt(2020, 11, 30).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -2),
+            NaiveDate::from_ymd_opt(2020, 10, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -10),
+            NaiveDate::from_ymd_opt(2020, 2, 29).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -12),
+            NaiveDate::from_ymd_opt(2019, 12, 31).unwrap()
+        );
+        assert_eq!(
+            shift_months(base, -18),
+            NaiveDate::from_ymd_opt(2019, 6, 30).unwrap()
+        );
     }
 
     #[test]
     fn test_shift_months_datetime() {
-        let date = NaiveDate::from_ymd(2020, 1, 31);
-        let o_clock = NaiveTime::from_hms(1, 2, 3);
+        let date = NaiveDate::from_ymd_opt(2020, 1, 31).unwrap();
+        let o_clock = NaiveTime::from_hms_opt(1, 2, 3).unwrap();
 
         let base = NaiveDateTime::new(date, o_clock);
 
         assert_eq!(
             shift_months(base, 0).date(),
-            NaiveDate::from_ymd(2020, 1, 31)
+            NaiveDate::from_ymd_opt(2020, 1, 31).unwrap()
         );
         assert_eq!(
             shift_months(base, 1).date(),
-            NaiveDate::from_ymd(2020, 2, 29)
+            NaiveDate::from_ymd_opt(2020, 2, 29).unwrap()
         );
         assert_eq!(
             shift_months(base, 2).date(),
-            NaiveDate::from_ymd(2020, 3, 31)
+            NaiveDate::from_ymd_opt(2020, 3, 31).unwrap()
         );
         assert_eq!(shift_months(base, 0).time(), o_clock);
         assert_eq!(shift_months(base, 1).time(), o_clock);
diff --git a/arrow-array/src/temporal_conversions.rs b/arrow-array/src/temporal_conversions.rs
index a4d910cc8..f1f3f36d3 100644
--- a/arrow-array/src/temporal_conversions.rs
+++ b/arrow-array/src/temporal_conversions.rs
@@ -252,7 +252,7 @@ pub fn as_time<T: ArrowPrimitiveType>(v: i64) -> Option<NaiveTime> {
             _ => None,
         },
         DataType::Timestamp(_, _) => as_datetime::<T>(v).map(|datetime| datetime.time()),
-        DataType::Date32 | DataType::Date64 => Some(NaiveTime::from_hms(0, 0, 0)),
+        DataType::Date32 | DataType::Date64 => NaiveTime::from_hms_opt(0, 0, 0),
         DataType::Interval(_) => None,
         _ => None,
     }
diff --git a/arrow-array/src/timezone.rs b/arrow-array/src/timezone.rs
index 7bd597904..fd8c099c2 100644
--- a/arrow-array/src/timezone.rs
+++ b/arrow-array/src/timezone.rs
@@ -158,8 +158,8 @@ mod private {
         #[test]
         fn test_with_timezone() {
             let vals = [
-                Utc.timestamp_millis(37800000),
-                Utc.timestamp_millis(86339000),
+                Utc.timestamp_millis_opt(37800000).unwrap(),
+                Utc.timestamp_millis_opt(86339000).unwrap(),
             ];
 
             assert_eq!(10, vals[0].hour());
@@ -175,8 +175,8 @@ mod private {
         fn test_using_chrono_tz_and_utc_naive_date_time() {
             let sydney_tz = "Australia/Sydney".to_string();
             let tz: Tz = sydney_tz.parse().unwrap();
-            let sydney_offset_without_dst = FixedOffset::east(10 * 60 * 60);
-            let sydney_offset_with_dst = FixedOffset::east(11 * 60 * 60);
+            let sydney_offset_without_dst = FixedOffset::east_opt(10 * 60 * 60).unwrap();
+            let sydney_offset_with_dst = FixedOffset::east_opt(11 * 60 * 60).unwrap();
             // Daylight savings ends
             // When local daylight time was about to reach
             // Sunday, 4 April 2021, 3:00:00 am clocks were turned backward 1 hour to
@@ -188,32 +188,40 @@ mod private {
             // Sunday, 3 October 2021, 3:00:00 am local daylight time instead.
 
             // Sydney 2021-04-04T02:30:00+11:00 is 2021-04-03T15:30:00Z
-            let utc_just_before_sydney_dst_ends =
-                NaiveDate::from_ymd(2021, 4, 3).and_hms_nano(15, 30, 0, 0);
+            let utc_just_before_sydney_dst_ends = NaiveDate::from_ymd_opt(2021, 4, 3)
+                .unwrap()
+                .and_hms_nano_opt(15, 30, 0, 0)
+                .unwrap();
             assert_eq!(
                 tz.offset_from_utc_datetime(&utc_just_before_sydney_dst_ends)
                     .fix(),
                 sydney_offset_with_dst
             );
             // Sydney 2021-04-04T02:30:00+10:00 is 2021-04-03T16:30:00Z
-            let utc_just_after_sydney_dst_ends =
-                NaiveDate::from_ymd(2021, 4, 3).and_hms_nano(16, 30, 0, 0);
+            let utc_just_after_sydney_dst_ends = NaiveDate::from_ymd_opt(2021, 4, 3)
+                .unwrap()
+                .and_hms_nano_opt(16, 30, 0, 0)
+                .unwrap();
             assert_eq!(
                 tz.offset_from_utc_datetime(&utc_just_after_sydney_dst_ends)
                     .fix(),
                 sydney_offset_without_dst
             );
             // Sydney 2021-10-03T01:30:00+10:00 is 2021-10-02T15:30:00Z
-            let utc_just_before_sydney_dst_starts =
-                NaiveDate::from_ymd(2021, 10, 2).and_hms_nano(15, 30, 0, 0);
+            let utc_just_before_sydney_dst_starts = NaiveDate::from_ymd_opt(2021, 10, 2)
+                .unwrap()
+                .and_hms_nano_opt(15, 30, 0, 0)
+                .unwrap();
             assert_eq!(
                 tz.offset_from_utc_datetime(&utc_just_before_sydney_dst_starts)
                     .fix(),
                 sydney_offset_without_dst
             );
             // Sydney 2021-04-04T03:30:00+11:00 is 2021-10-02T16:30:00Z
-            let utc_just_after_sydney_dst_starts =
-                NaiveDate::from_ymd(2022, 10, 2).and_hms_nano(16, 30, 0, 0);
+            let utc_just_after_sydney_dst_starts = NaiveDate::from_ymd_opt(2022, 10, 2)
+                .unwrap()
+                .and_hms_nano_opt(16, 30, 0, 0)
+                .unwrap();
             assert_eq!(
                 tz.offset_from_utc_datetime(&utc_just_after_sydney_dst_starts)
                     .fix(),
@@ -300,7 +308,7 @@ mod tests {
 
     #[test]
     fn test_with_offset() {
-        let t = NaiveDate::from_ymd(2000, 1, 1);
+        let t = NaiveDate::from_ymd_opt(2000, 1, 1).unwrap();
 
         let tz: Tz = "-00:00".parse().unwrap();
         assert_eq!(tz.offset_from_utc_date(&t).fix().local_minus_utc(), 0);
diff --git a/arrow-array/src/types.rs b/arrow-array/src/types.rs
index 03ecef361..dd4d1ba42 100644
--- a/arrow-array/src/types.rs
+++ b/arrow-array/src/types.rs
@@ -327,7 +327,7 @@ impl Date32Type {
     ///
     /// * `i` - The Date32Type to convert
     pub fn to_naive_date(i: <Date32Type as ArrowPrimitiveType>::Native) -> NaiveDate {
-        let epoch = NaiveDate::from_ymd(1970, 1, 1);
+        let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
         epoch.add(Duration::days(i as i64))
     }
 
@@ -337,7 +337,7 @@ impl Date32Type {
     ///
     /// * `d` - The NaiveDate to convert
     pub fn from_naive_date(d: NaiveDate) -> <Date32Type as ArrowPrimitiveType>::Native {
-        let epoch = NaiveDate::from_ymd(1970, 1, 1);
+        let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
         d.sub(epoch).num_days() as <Date32Type as ArrowPrimitiveType>::Native
     }
 
@@ -400,7 +400,7 @@ impl Date64Type {
     ///
     /// * `i` - The Date64Type to convert
     pub fn to_naive_date(i: <Date64Type as ArrowPrimitiveType>::Native) -> NaiveDate {
-        let epoch = NaiveDate::from_ymd(1970, 1, 1);
+        let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
         epoch.add(Duration::milliseconds(i as i64))
     }
 
@@ -410,7 +410,7 @@ impl Date64Type {
     ///
     /// * `d` - The NaiveDate to convert
     pub fn from_naive_date(d: NaiveDate) -> <Date64Type as ArrowPrimitiveType>::Native {
-        let epoch = NaiveDate::from_ymd(1970, 1, 1);
+        let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
         d.sub(epoch).num_milliseconds() as <Date64Type as ArrowPrimitiveType>::Native
     }
 
diff --git a/arrow-cast/src/cast.rs b/arrow-cast/src/cast.rs
index bbd38fbc0..b3c0aaa82 100644
--- a/arrow-cast/src/cast.rs
+++ b/arrow-cast/src/cast.rs
@@ -6120,7 +6120,7 @@ mod tests {
     #[test]
     fn test_cast_utf8_to_date32() {
         use chrono::NaiveDate;
-        let from_ymd = chrono::NaiveDate::from_ymd;
+        let from_ymd = chrono::NaiveDate::from_ymd_opt;
         let since = chrono::NaiveDate::signed_duration_since;
 
         let a = StringArray::from(vec![
@@ -6135,13 +6135,19 @@ mod tests {
         let c = b.as_any().downcast_ref::<Date32Array>().unwrap();
 
         // test valid inputs
-        let date_value = since(NaiveDate::from_ymd(2000, 1, 1), from_ymd(1970, 1, 1))
-            .num_days() as i32;
+        let date_value = since(
+            NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
+            from_ymd(1970, 1, 1).unwrap(),
+        )
+        .num_days() as i32;
         assert!(c.is_valid(0)); // "2000-01-01"
         assert_eq!(date_value, c.value(0));
 
-        let date_value = since(NaiveDate::from_ymd(2000, 2, 2), from_ymd(1970, 1, 1))
-            .num_days() as i32;
+        let date_value = since(
+            NaiveDate::from_ymd_opt(2000, 2, 2).unwrap(),
+            from_ymd(1970, 1, 1).unwrap(),
+        )
+        .num_days() as i32;
         assert!(c.is_valid(1)); // "2000-2-2"
         assert_eq!(date_value, c.value(1));
 
diff --git a/arrow-cast/src/parse.rs b/arrow-cast/src/parse.rs
index 126beb902..b93d6c800 100644
--- a/arrow-cast/src/parse.rs
+++ b/arrow-cast/src/parse.rs
@@ -305,8 +305,8 @@ mod tests {
         // timezone the test machine is running. Thus it is still
         // somewhat susceptible to bugs in the use of chrono
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(2020, 9, 8),
-            NaiveTime::from_hms_nano(13, 42, 29, 190855000),
+            NaiveDate::from_ymd_opt(2020, 9, 8).unwrap(),
+            NaiveTime::from_hms_nano_opt(13, 42, 29, 190855000).unwrap(),
         );
 
         // Ensure both T and ' ' variants work
@@ -323,8 +323,8 @@ mod tests {
         // Also ensure that parsing timestamps with no fractional
         // second part works as well
         let naive_datetime_whole_secs = NaiveDateTime::new(
-            NaiveDate::from_ymd(2020, 9, 8),
-            NaiveTime::from_hms(13, 42, 29),
+            NaiveDate::from_ymd_opt(2020, 9, 8).unwrap(),
+            NaiveTime::from_hms_opt(13, 42, 29).unwrap(),
         );
 
         // Ensure both T and ' ' variants work
@@ -380,8 +380,8 @@ mod tests {
         // string without timezone should always output the same regardless the local or session timezone
 
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(2020, 9, 8),
-            NaiveTime::from_hms_nano(13, 42, 29, 190855000),
+            NaiveDate::from_ymd_opt(2020, 9, 8).unwrap(),
+            NaiveTime::from_hms_nano_opt(13, 42, 29, 190855000).unwrap(),
         );
 
         // Ensure both T and ' ' variants work
@@ -396,8 +396,8 @@ mod tests {
         );
 
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(2020, 9, 8),
-            NaiveTime::from_hms_nano(13, 42, 29, 0),
+            NaiveDate::from_ymd_opt(2020, 9, 8).unwrap(),
+            NaiveTime::from_hms_nano_opt(13, 42, 29, 0).unwrap(),
         );
 
         // Ensure both T and ' ' variants work
diff --git a/arrow-csv/src/reader.rs b/arrow-csv/src/reader.rs
index 2fb6493e1..0bf05960a 100644
--- a/arrow-csv/src/reader.rs
+++ b/arrow-csv/src/reader.rs
@@ -1701,8 +1701,8 @@ mod tests {
             0
         );
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(2018, 11, 13),
-            NaiveTime::from_hms_nano(17, 11, 10, 0),
+            NaiveDate::from_ymd_opt(2018, 11, 13).unwrap(),
+            NaiveTime::from_hms_nano_opt(17, 11, 10, 0).unwrap(),
         );
         assert_eq!(
             parse_item::<TimestampMicrosecondType>("2018-11-13T17:11:10").unwrap(),
@@ -1713,16 +1713,16 @@ mod tests {
             naive_datetime.timestamp_nanos() / 1000
         );
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(2018, 11, 13),
-            NaiveTime::from_hms_nano(17, 11, 10, 11000000),
+            NaiveDate::from_ymd_opt(2018, 11, 13).unwrap(),
+            NaiveTime::from_hms_nano_opt(17, 11, 10, 11000000).unwrap(),
         );
         assert_eq!(
             parse_item::<TimestampMicrosecondType>("2018-11-13T17:11:10.011").unwrap(),
             naive_datetime.timestamp_nanos() / 1000
         );
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(1900, 2, 28),
-            NaiveTime::from_hms_nano(12, 34, 56, 0),
+            NaiveDate::from_ymd_opt(1900, 2, 28).unwrap(),
+            NaiveTime::from_hms_nano_opt(12, 34, 56, 0).unwrap(),
         );
         assert_eq!(
             parse_item::<TimestampMicrosecondType>("1900-02-28T12:34:56").unwrap(),
@@ -1737,8 +1737,8 @@ mod tests {
             0
         );
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(2018, 11, 13),
-            NaiveTime::from_hms_nano(17, 11, 10, 0),
+            NaiveDate::from_ymd_opt(2018, 11, 13).unwrap(),
+            NaiveTime::from_hms_nano_opt(17, 11, 10, 0).unwrap(),
         );
         assert_eq!(
             parse_item::<TimestampNanosecondType>("2018-11-13T17:11:10").unwrap(),
@@ -1749,16 +1749,16 @@ mod tests {
             naive_datetime.timestamp_nanos()
         );
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(2018, 11, 13),
-            NaiveTime::from_hms_nano(17, 11, 10, 11000000),
+            NaiveDate::from_ymd_opt(2018, 11, 13).unwrap(),
+            NaiveTime::from_hms_nano_opt(17, 11, 10, 11000000).unwrap(),
         );
         assert_eq!(
             parse_item::<TimestampNanosecondType>("2018-11-13T17:11:10.011").unwrap(),
             naive_datetime.timestamp_nanos()
         );
         let naive_datetime = NaiveDateTime::new(
-            NaiveDate::from_ymd(1900, 2, 28),
-            NaiveTime::from_hms_nano(12, 34, 56, 0),
+            NaiveDate::from_ymd_opt(1900, 2, 28).unwrap(),
+            NaiveTime::from_hms_nano_opt(12, 34, 56, 0).unwrap(),
         );
         assert_eq!(
             parse_item::<TimestampNanosecondType>("1900-02-28T12:34:56").unwrap(),
diff --git a/arrow/benches/cast_kernels.rs b/arrow/benches/cast_kernels.rs
index 2c3d8cd16..e93c78608 100644
--- a/arrow/benches/cast_kernels.rs
+++ b/arrow/benches/cast_kernels.rs
@@ -52,7 +52,8 @@ fn build_utf8_date_array(size: usize, with_nulls: bool) -> ArrayRef {
         if with_nulls && rng.gen::<f32>() > 0.8 {
             builder.append_null();
         } else {
-            let string = NaiveDate::from_num_days_from_ce(rng.sample(range))
+            let string = NaiveDate::from_num_days_from_ce_opt(rng.sample(range))
+                .unwrap()
                 .format("%Y-%m-%d")
                 .to_string();
             builder.append_value(&string);
@@ -73,7 +74,8 @@ fn build_utf8_date_time_array(size: usize, with_nulls: bool) -> ArrayRef {
         if with_nulls && rng.gen::<f32>() > 0.8 {
             builder.append_null();
         } else {
-            let string = NaiveDateTime::from_timestamp(rng.sample(range), 0)
+            let string = NaiveDateTime::from_timestamp_opt(rng.sample(range), 0)
+                .unwrap()
                 .format("%Y-%m-%dT%H:%M:%S")
                 .to_string();
             builder.append_value(&string);
diff --git a/arrow/src/compute/kernels/arithmetic.rs b/arrow/src/compute/kernels/arithmetic.rs
index 328ce02e4..a99a90204 100644
--- a/arrow/src/compute/kernels/arithmetic.rs
+++ b/arrow/src/compute/kernels/arithmetic.rs
@@ -1644,7 +1644,7 @@ mod tests {
     #[test]
     fn test_date32_month_add() {
         let a = Date32Array::from(vec![Date32Type::from_naive_date(
-            NaiveDate::from_ymd(2000, 1, 1),
+            NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
         )]);
         let b =
             IntervalYearMonthArray::from(vec![IntervalYearMonthType::make_value(1, 2)]);
@@ -1652,28 +1652,28 @@ mod tests {
         let c = c.as_any().downcast_ref::<Date32Array>().unwrap();
         assert_eq!(
             c.value(0),
-            Date32Type::from_naive_date(NaiveDate::from_ymd(2001, 3, 1))
+            Date32Type::from_naive_date(NaiveDate::from_ymd_opt(2001, 3, 1).unwrap())
         );
     }
 
     #[test]
     fn test_date32_day_time_add() {
         let a = Date32Array::from(vec![Date32Type::from_naive_date(
-            NaiveDate::from_ymd(2000, 1, 1),
+            NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
         )]);
         let b = IntervalDayTimeArray::from(vec![IntervalDayTimeType::make_value(1, 2)]);
         let c = add_dyn(&a, &b).unwrap();
         let c = c.as_any().downcast_ref::<Date32Array>().unwrap();
         assert_eq!(
             c.value(0),
-            Date32Type::from_naive_date(NaiveDate::from_ymd(2000, 1, 2))
+            Date32Type::from_naive_date(NaiveDate::from_ymd_opt(2000, 1, 2).unwrap())
         );
     }
 
     #[test]
     fn test_date32_month_day_nano_add() {
         let a = Date32Array::from(vec![Date32Type::from_naive_date(
-            NaiveDate::from_ymd(2000, 1, 1),
+            NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
         )]);
         let b =
             IntervalMonthDayNanoArray::from(vec![IntervalMonthDayNanoType::make_value(
@@ -1683,14 +1683,14 @@ mod tests {
         let c = c.as_any().downcast_ref::<Date32Array>().unwrap();
         assert_eq!(
             c.value(0),
-            Date32Type::from_naive_date(NaiveDate::from_ymd(2000, 2, 3))
+            Date32Type::from_naive_date(NaiveDate::from_ymd_opt(2000, 2, 3).unwrap())
         );
     }
 
     #[test]
     fn test_date64_month_add() {
         let a = Date64Array::from(vec![Date64Type::from_naive_date(
-            NaiveDate::from_ymd(2000, 1, 1),
+            NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
         )]);
         let b =
             IntervalYearMonthArray::from(vec![IntervalYearMonthType::make_value(1, 2)]);
@@ -1698,28 +1698,28 @@ mod tests {
         let c = c.as_any().downcast_ref::<Date64Array>().unwrap();
         assert_eq!(
             c.value(0),
-            Date64Type::from_naive_date(NaiveDate::from_ymd(2001, 3, 1))
+            Date64Type::from_naive_date(NaiveDate::from_ymd_opt(2001, 3, 1).unwrap())
         );
     }
 
     #[test]
     fn test_date64_day_time_add() {
         let a = Date64Array::from(vec![Date64Type::from_naive_date(
-            NaiveDate::from_ymd(2000, 1, 1),
+            NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
         )]);
         let b = IntervalDayTimeArray::from(vec![IntervalDayTimeType::make_value(1, 2)]);
         let c = add_dyn(&a, &b).unwrap();
         let c = c.as_any().downcast_ref::<Date64Array>().unwrap();
         assert_eq!(
             c.value(0),
-            Date64Type::from_naive_date(NaiveDate::from_ymd(2000, 1, 2))
+            Date64Type::from_naive_date(NaiveDate::from_ymd_opt(2000, 1, 2).unwrap())
         );
     }
 
     #[test]
     fn test_date64_month_day_nano_add() {
         let a = Date64Array::from(vec![Date64Type::from_naive_date(
-            NaiveDate::from_ymd(2000, 1, 1),
+            NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
         )]);
         let b =
             IntervalMonthDayNanoArray::from(vec![IntervalMonthDayNanoType::make_value(
@@ -1729,7 +1729,7 @@ mod tests {
         let c = c.as_any().downcast_ref::<Date64Array>().unwrap();
         assert_eq!(
             c.value(0),
-            Date64Type::from_naive_date(NaiveDate::from_ymd(2000, 2, 3))
+            Date64Type::from_naive_date(NaiveDate::from_ymd_opt(2000, 2, 3).unwrap())
         );
     }
 
diff --git a/parquet/src/record/api.rs b/parquet/src/record/api.rs
index d7e1e7550..02cb94765 100644
--- a/parquet/src/record/api.rs
+++ b/parquet/src/record/api.rs
@@ -795,7 +795,9 @@ impl fmt::Display for Field {
 #[inline]
 fn convert_date_to_string(value: u32) -> String {
     static NUM_SECONDS_IN_DAY: i64 = 60 * 60 * 24;
-    let dt = Utc.timestamp(value as i64 * NUM_SECONDS_IN_DAY, 0).date();
+    let dt = Utc
+        .timestamp_opt(value as i64 * NUM_SECONDS_IN_DAY, 0)
+        .unwrap();
     format!("{}", dt.format("%Y-%m-%d %:z"))
 }
 
@@ -804,7 +806,7 @@ fn convert_date_to_string(value: u32) -> String {
 /// Datetime is displayed in local timezone.
 #[inline]
 fn convert_timestamp_secs_to_string(value: i64) -> String {
-    let dt = Utc.timestamp(value, 0);
+    let dt = Utc.timestamp_opt(value, 0).unwrap();
     format!("{}", dt.format("%Y-%m-%d %H:%M:%S %:z"))
 }
 
@@ -1075,7 +1077,10 @@ mod tests {
     #[test]
     fn test_convert_date_to_string() {
         fn check_date_conversion(y: u32, m: u32, d: u32) {
-            let datetime = chrono::NaiveDate::from_ymd(y as i32, m, d).and_hms(0, 0, 0);
+            let datetime = chrono::NaiveDate::from_ymd_opt(y as i32, m, d)
+                .unwrap()
+                .and_hms_opt(0, 0, 0)
+                .unwrap();
             let dt = Utc.from_utc_datetime(&datetime);
             let res = convert_date_to_string((dt.timestamp() / 60 / 60 / 24) as u32);
             let exp = format!("{}", dt.format("%Y-%m-%d %:z"));
@@ -1092,7 +1097,10 @@ mod tests {
     #[test]
     fn test_convert_timestamp_millis_to_string() {
         fn check_datetime_conversion(y: u32, m: u32, d: u32, h: u32, mi: u32, s: u32) {
-            let datetime = chrono::NaiveDate::from_ymd(y as i32, m, d).and_hms(h, mi, s);
+            let datetime = chrono::NaiveDate::from_ymd_opt(y as i32, m, d)
+                .unwrap()
+                .and_hms_opt(h, mi, s)
+                .unwrap();
             let dt = Utc.from_utc_datetime(&datetime);
             let res = convert_timestamp_millis_to_string(dt.timestamp_millis() as u64);
             let exp = format!("{}", dt.format("%Y-%m-%d %H:%M:%S %:z"));
@@ -1110,7 +1118,10 @@ mod tests {
     #[test]
     fn test_convert_timestamp_micros_to_string() {
         fn check_datetime_conversion(y: u32, m: u32, d: u32, h: u32, mi: u32, s: u32) {
-            let datetime = chrono::NaiveDate::from_ymd(y as i32, m, d).and_hms(h, mi, s);
+            let datetime = chrono::NaiveDate::from_ymd_opt(y as i32, m, d)
+                .unwrap()
+                .and_hms_opt(h, mi, s)
+                .unwrap();
             let dt = Utc.from_utc_datetime(&datetime);
             let res = convert_timestamp_micros_to_string(dt.timestamp_micros() as u64);
             let exp = format!("{}", dt.format("%Y-%m-%d %H:%M:%S %:z"));