Skip to content

Commit 9ec9f57

Browse files
Deprecate ArrowTimestampType::make_value in favor of from_naive_datetime (#9491)
Mark ArrowTimestampType::make_value as deprecated and migrate internal callers to the newer from_naive_datetime API. # Which issue does this PR close? - Closes #9490 . # Rationale for this change Follow-up from PR #9345. # What changes are included in this PR? Mark ArrowTimestampType::make_value as deprecated and migrate internal callers to the newer from_naive_datetime API. # Are these changes tested? YES. # Are there any user-facing changes? Migration Path: Users should replace: ```rust // Old TimestampSecondType::make_value(naive) ``` With: ```rust // New TimestampSecondType::from_naive_datetime(naive, None) ```
1 parent a7acf3d commit 9ec9f57

File tree

6 files changed

+24
-26
lines changed

6 files changed

+24
-26
lines changed

arrow-arith/src/numeric.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,10 @@ mod tests {
13201320
"1960-01-30T04:23:20Z",
13211321
]
13221322
.into_iter()
1323-
.map(|x| T::make_value(DateTime::parse_from_rfc3339(x).unwrap().naive_utc()).unwrap())
1323+
.map(|x| {
1324+
T::from_naive_datetime(DateTime::parse_from_rfc3339(x).unwrap().naive_utc(), None)
1325+
.unwrap()
1326+
})
13241327
.collect();
13251328

13261329
let a = PrimitiveArray::<T>::new(values, None);

arrow-array/src/types.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ pub trait ArrowTimestampType: ArrowTemporalType<Native = i64> {
324324
/// Creates a ArrowTimestampType::Native from the provided [`NaiveDateTime`]
325325
///
326326
/// See [`DataType::Timestamp`] for more information on timezone handling
327+
#[deprecated(since = "58.1.0", note = "Use from_naive_datetime instead")]
327328
fn make_value(naive: NaiveDateTime) -> Option<i64>;
328329

329330
/// Creates a timestamp value from a [`DateTime`] in any timezone.
@@ -350,7 +351,7 @@ pub trait ArrowTimestampType: ArrowTemporalType<Native = i64> {
350351
chrono::offset::LocalResult::Ambiguous(dt1, _) => Self::from_datetime(dt1),
351352
chrono::offset::LocalResult::None => None,
352353
},
353-
None => Self::make_value(naive),
354+
None => Self::from_datetime(naive.and_utc()),
354355
}
355356
}
356357
}
@@ -416,8 +417,7 @@ fn add_year_months<T: ArrowTimestampType>(
416417
let months = IntervalYearMonthType::to_months(delta);
417418
let res = as_datetime_with_timezone::<T>(timestamp, tz)?;
418419
let res = add_months_datetime(res, months)?;
419-
let res = res.naive_utc();
420-
T::make_value(res)
420+
T::from_naive_datetime(res.naive_utc(), None)
421421
}
422422

423423
fn add_day_time<T: ArrowTimestampType>(
@@ -429,8 +429,7 @@ fn add_day_time<T: ArrowTimestampType>(
429429
let res = as_datetime_with_timezone::<T>(timestamp, tz)?;
430430
let res = add_days_datetime(res, days)?;
431431
let res = res.checked_add_signed(Duration::try_milliseconds(ms as i64)?)?;
432-
let res = res.naive_utc();
433-
T::make_value(res)
432+
T::from_naive_datetime(res.naive_utc(), None)
434433
}
435434

436435
fn add_month_day_nano<T: ArrowTimestampType>(
@@ -443,8 +442,7 @@ fn add_month_day_nano<T: ArrowTimestampType>(
443442
let res = add_months_datetime(res, months)?;
444443
let res = add_days_datetime(res, days)?;
445444
let res = res.checked_add_signed(Duration::nanoseconds(nanos))?;
446-
let res = res.naive_utc();
447-
T::make_value(res)
445+
T::from_naive_datetime(res.naive_utc(), None)
448446
}
449447

450448
fn subtract_year_months<T: ArrowTimestampType>(
@@ -455,8 +453,7 @@ fn subtract_year_months<T: ArrowTimestampType>(
455453
let months = IntervalYearMonthType::to_months(delta);
456454
let res = as_datetime_with_timezone::<T>(timestamp, tz)?;
457455
let res = sub_months_datetime(res, months)?;
458-
let res = res.naive_utc();
459-
T::make_value(res)
456+
T::from_naive_datetime(res.naive_utc(), None)
460457
}
461458

462459
fn subtract_day_time<T: ArrowTimestampType>(
@@ -468,8 +465,7 @@ fn subtract_day_time<T: ArrowTimestampType>(
468465
let res = as_datetime_with_timezone::<T>(timestamp, tz)?;
469466
let res = sub_days_datetime(res, days)?;
470467
let res = res.checked_sub_signed(Duration::try_milliseconds(ms as i64)?)?;
471-
let res = res.naive_utc();
472-
T::make_value(res)
468+
T::from_naive_datetime(res.naive_utc(), None)
473469
}
474470

475471
fn subtract_month_day_nano<T: ArrowTimestampType>(
@@ -482,8 +478,7 @@ fn subtract_month_day_nano<T: ArrowTimestampType>(
482478
let res = sub_months_datetime(res, months)?;
483479
let res = sub_days_datetime(res, days)?;
484480
let res = res.checked_sub_signed(Duration::nanoseconds(nanos))?;
485-
let res = res.naive_utc();
486-
T::make_value(res)
481+
T::from_naive_datetime(res.naive_utc(), None)
487482
}
488483

489484
impl TimestampSecondType {

arrow-cast/src/cast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,7 @@ fn adjust_timestamp_to_timezone<T: ArrowTimestampType>(
25072507
let adjust = |o| {
25082508
let local = as_datetime::<T>(o)?;
25092509
let offset = to_tz.offset_from_local_datetime(&local).single()?;
2510-
T::make_value(local - offset.fix())
2510+
T::from_naive_datetime(local - offset.fix(), None)
25112511
};
25122512
let adjusted = if cast_options.safe {
25132513
array.unary_opt::<_, Int64Type>(adjust)

arrow-cast/src/cast/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn cast_string_to_timestamp_impl<
168168
let iter = iter.map(|v| {
169169
v.and_then(|v| {
170170
let naive = string_to_datetime(tz, v).ok()?.naive_utc();
171-
T::make_value(naive)
171+
T::from_naive_datetime(naive, None)
172172
})
173173
});
174174
// Benefit:
@@ -182,7 +182,7 @@ fn cast_string_to_timestamp_impl<
182182
.map(|v| {
183183
v.map(|v| {
184184
let naive = string_to_datetime(tz, v)?.naive_utc();
185-
T::make_value(naive).ok_or_else(|| match T::UNIT {
185+
T::from_naive_datetime(naive, None).ok_or_else(|| match T::UNIT {
186186
TimeUnit::Nanosecond => ArrowError::CastError(format!(
187187
"Overflow converting {naive} to Nanosecond. The dates that can be represented as nanoseconds have to be between 1677-09-21T00:12:44.0 and 2262-04-11T23:47:16.854775804"
188188
)),

arrow/tests/arithmetic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn test_timestamp_with_timezone_impl<T: ArrowTimestampType>(tz_str: &str) {
7676
.naive_utc(),
7777
]
7878
.into_iter()
79-
.map(|x| T::make_value(x).unwrap())
79+
.map(|x| T::from_naive_datetime(x, None).unwrap())
8080
.collect();
8181

8282
let a = PrimitiveArray::<T>::new(values, None).with_timezone(tz_str);

parquet-variant-compute/src/type_conversion.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl_timestamp_from_variant!(
109109
if timestamp.nanosecond() != 0 {
110110
None
111111
} else {
112-
Self::make_value(timestamp)
112+
Self::from_naive_datetime(timestamp, None)
113113
}
114114
}
115115
);
@@ -122,7 +122,7 @@ impl_timestamp_from_variant!(
122122
if timestamp.nanosecond() != 0 {
123123
None
124124
} else {
125-
Self::make_value(timestamp.naive_utc())
125+
Self::from_naive_datetime(timestamp.naive_utc(), None)
126126
}
127127
}
128128
);
@@ -135,7 +135,7 @@ impl_timestamp_from_variant!(
135135
if timestamp.nanosecond() % 1_000_000 != 0 {
136136
None
137137
} else {
138-
Self::make_value(timestamp)
138+
Self::from_naive_datetime(timestamp, None)
139139
}
140140
}
141141
);
@@ -148,33 +148,33 @@ impl_timestamp_from_variant!(
148148
if timestamp.nanosecond() % 1_000_000 != 0 {
149149
None
150150
} else {
151-
Self::make_value(timestamp.naive_utc())
151+
Self::from_naive_datetime(timestamp.naive_utc(), None)
152152
}
153153
}
154154
);
155155
impl_timestamp_from_variant!(
156156
datatypes::TimestampMicrosecondType,
157157
as_timestamp_ntz_micros,
158158
ntz = true,
159-
Self::make_value,
159+
|timestamp| Self::from_naive_datetime(timestamp, None),
160160
);
161161
impl_timestamp_from_variant!(
162162
datatypes::TimestampMicrosecondType,
163163
as_timestamp_micros,
164164
ntz = false,
165-
|timestamp| Self::make_value(timestamp.naive_utc())
165+
|timestamp| Self::from_naive_datetime(timestamp.naive_utc(), None)
166166
);
167167
impl_timestamp_from_variant!(
168168
datatypes::TimestampNanosecondType,
169169
as_timestamp_ntz_nanos,
170170
ntz = true,
171-
Self::make_value
171+
|timestamp| Self::from_naive_datetime(timestamp, None)
172172
);
173173
impl_timestamp_from_variant!(
174174
datatypes::TimestampNanosecondType,
175175
as_timestamp_nanos,
176176
ntz = false,
177-
|timestamp| Self::make_value(timestamp.naive_utc())
177+
|timestamp| Self::from_naive_datetime(timestamp.naive_utc(), None)
178178
);
179179

180180
/// Returns the unscaled integer representation for Arrow decimal type `O`

0 commit comments

Comments
 (0)