Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/enums/collections/temporal_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::{
sync::Arc,
};

use crate::{Bitmask, DatetimeArray, MaskedArray};
use crate::{Bitmask, DatetimeArray, MaskedArray, TimeUnit};
use crate::{
enums::{error::MinarrowError, shape_dim::ShapeDim},
traits::{concatenate::Concatenate, shape::Shape},
Expand Down Expand Up @@ -102,6 +102,20 @@ impl TemporalArray {
}
}

/// The time unit the samples are measured in i.e. seconds, milliseconds,
/// microseconds, nanoseconds, or days.
///
/// Returns `None` for the `Null` placeholder variant, which carries no
/// datetime payload and therefore no unit.
#[inline]
pub fn time_unit(&self) -> Option<TimeUnit> {
match self {
TemporalArray::Datetime32(arr) => Some(arr.time_unit),
TemporalArray::Datetime64(arr) => Some(arr.time_unit),
TemporalArray::Null => None,
}
}

/// Removes the rows in `[start, end)`, shifting later rows left.
/// A shared inner array is cloned first i.e. copy-on-write.
///
Expand Down Expand Up @@ -325,7 +339,7 @@ impl Concatenate for TemporalArray {
use crate::DatetimeOps;

#[cfg(feature = "datetime_ops")]
use crate::enums::time_units::{TimePeriod, TimeUnit};
use crate::enums::time_units::TimePeriod;

#[cfg(feature = "datetime_ops")]
use time::Duration;
Expand Down
19 changes: 12 additions & 7 deletions src/structs/views/collections/temporal_array_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use crate::enums::shape_dim::ShapeDim;
use crate::traits::concatenate::Concatenate;
use crate::traits::print::MAX_PREVIEW;
use crate::traits::shape::Shape;
use crate::{Array, ArrayV, BitmaskV, MaskedArray, TemporalArray};
use crate::{Array, ArrayV, BitmaskV, MaskedArray, TemporalArray, TimeUnit};

/// # TemporalArrayView
///
Expand Down Expand Up @@ -183,6 +183,17 @@ impl TemporalArrayV {
self.len
}

/// The time unit the samples are measured in i.e. seconds, milliseconds,
/// microseconds, nanoseconds, or days.
///
/// Reads the unit off the backing datetime array, so the window's offset
/// and length do not affect it. Returns `None` for the `Null` placeholder
/// variant, which carries no datetime payload and therefore no unit.
#[inline]
pub fn time_unit(&self) -> Option<TimeUnit> {
self.array.time_unit()
}

/// Returns the full backing array wrapped as an `Array` enum, ignoring the view's offset and length.
///
/// Use this to access inner array methods. The returned array is the unwindowed original.
Expand Down Expand Up @@ -338,7 +349,6 @@ impl Display for TemporalArrayV {
{
use time::OffsetDateTime;

use crate::TimeUnit;
let unit = match &self.array {
TemporalArray::Datetime32(arr) => &arr.time_unit,
TemporalArray::Datetime64(arr) => &arr.time_unit,
Expand Down Expand Up @@ -389,8 +399,6 @@ impl Display for TemporalArrayV {

#[cfg(not(feature = "datetime_ops"))]
{
use crate::TimeUnit;

let unit = match &self.array {
TemporalArray::Datetime32(arr) => &arr.time_unit,
TemporalArray::Datetime64(arr) => &arr.time_unit,
Expand Down Expand Up @@ -422,9 +430,6 @@ impl Display for TemporalArrayV {
#[cfg(feature = "datetime_ops")]
use crate::DatetimeOps;

#[cfg(feature = "datetime_ops")]
use crate::enums::time_units::TimeUnit;

#[cfg(feature = "datetime_ops")]
use time::Duration;

Expand Down
Loading