Skip to content

Commit

Permalink
Derive Copy for TimeUnit and IntervalUnit (#5840)
Browse files Browse the repository at this point in the history
* Derive `Copy` for `TimeUnit` and `IntervalUnit`

* Fix clippy warnings

* Rustfmt
  • Loading branch information
mbrobbel authored Jun 4, 2024
1 parent f42218a commit bca2f3a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ pub fn cast_with_options(
let array = cast_with_options(array, &Int64, cast_options)?;
Ok(make_timestamp_array(
array.as_primitive(),
unit.clone(),
*unit,
tz.clone(),
))
}
Expand Down Expand Up @@ -1721,11 +1721,7 @@ pub fn cast_with_options(
}
_ => converted,
};
Ok(make_timestamp_array(
&adjusted,
to_unit.clone(),
to_tz.clone(),
))
Ok(make_timestamp_array(&adjusted, *to_unit, to_tz.clone()))
}
(Timestamp(TimeUnit::Microsecond, _), Date32) => {
timestamp_to_date32(array.as_primitive::<TimestampMicrosecondType>())
Expand Down Expand Up @@ -4020,7 +4016,7 @@ mod tests {
TimeUnit::Microsecond,
TimeUnit::Nanosecond,
] {
let to_type = DataType::Timestamp(time_unit.clone(), None);
let to_type = DataType::Timestamp(*time_unit, None);
let b = cast(array, &to_type).unwrap();

match time_unit {
Expand Down
4 changes: 2 additions & 2 deletions arrow-schema/src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pub enum DataType {
}

/// An absolute length of time in seconds, milliseconds, microseconds or nanoseconds.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TimeUnit {
/// Time in seconds.
Expand All @@ -341,7 +341,7 @@ pub enum TimeUnit {
}

/// YEAR_MONTH, DAY_TIME, MONTH_DAY_NANO interval in SQL style.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum IntervalUnit {
/// Indicates the number of elapsed whole months, stored as 4-byte integers.
Expand Down

0 comments on commit bca2f3a

Please sign in to comment.