Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for extracting hours/minutes/seconds/etc. from Time32/Time64 type in temporal kernels #5261

Closed
Jefffrey opened this issue Dec 31, 2023 · 1 comment · Fixed by #5337
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@Jefffrey
Copy link
Contributor

Jefffrey commented Dec 31, 2023

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

In temporal kernels, only hour currently supports Time32/Time64 types:

pub fn hour<T>(array: &PrimitiveArray<T>) -> Result<Int32Array, ArrowError>
where
T: ArrowTemporalType + ArrowNumericType,
i64: From<T::Native>,
{
let b = Int32Builder::with_capacity(array.len());
match array.data_type() {
DataType::Time32(_) | DataType::Time64(_) => {
let iter = ArrayIter::new(array);
Ok(as_time_with_op::<&PrimitiveArray<T>, T, _>(iter, b, |t| {
t.hour() as i32
}))
}
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
Ok(as_datetime_with_op::<&PrimitiveArray<T>, T, _>(
iter,
b,
|t| t.hour() as i32,
))
}
DataType::Timestamp(_, Some(tz)) => {
let iter = ArrayIter::new(array);
extract_component_from_datetime_array::<&PrimitiveArray<T>, T, _>(iter, b, tz, |t| {
t.hour() as i32
})
}
_ => return_compute_error_with!("hour does not support", array.data_type()),
}
}

Note this seems to only work for hour and not hour_dyn:

/// Extracts the hours of a given array as an array of integers within
/// the range of [0, 23]. If the given array isn't temporal primitive or dictionary array,
/// an `Err` will be returned.
pub fn hour_dyn(array: &dyn Array) -> Result<ArrayRef, ArrowError> {
time_fraction_dyn(array, "hour", |t| t.hour() as i32)
}

Describe the solution you'd like

Be able to call the following for Time32/Time64 types:

  • hour
  • minute
  • second
  • millisecond
  • microsecond
  • nanosecond

Describe alternatives you've considered

Additional context

@Jefffrey Jefffrey added the enhancement Any new improvement worthy of a entry in the changelog label Dec 31, 2023
@tustvold tustvold added the arrow Changes to the arrow crate label Mar 1, 2024
@tustvold
Copy link
Contributor

tustvold commented Mar 1, 2024

label_issue.py automatically added labels {'arrow'} from #5337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
2 participants