Skip to content
Closed
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
58 changes: 29 additions & 29 deletions src/enums/collections/numeric_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ macro_rules! decimal_to_str {
}

impl NumericArray {
/// Returns the variant name as a short string, for example "Int32" or "Float64".
pub fn variant_name(&self) -> &'static str {
match self {
#[cfg(feature = "extended_numeric_types")]
NumericArray::Int8(_) => "Int8",
#[cfg(feature = "extended_numeric_types")]
NumericArray::Int16(_) => "Int16",
NumericArray::Int32(_) => "Int32",
NumericArray::Int64(_) => "Int64",
#[cfg(feature = "extended_numeric_types")]
NumericArray::UInt8(_) => "UInt8",
#[cfg(feature = "extended_numeric_types")]
NumericArray::UInt16(_) => "UInt16",
NumericArray::UInt32(_) => "UInt32",
NumericArray::UInt64(_) => "UInt64",
NumericArray::Float32(_) => "Float32",
NumericArray::Float64(_) => "Float64",
#[cfg(feature = "decimal")]
NumericArray::Decimal32(_) => "Decimal32",
#[cfg(feature = "decimal")]
NumericArray::Decimal64(_) => "Decimal64",
#[cfg(feature = "decimal")]
NumericArray::Decimal128(_) => "Decimal128",
NumericArray::Null => "Null",
}
}

/// Returns the logical length of the numeric array.
#[inline]
pub fn len(&self) -> usize {
Expand Down Expand Up @@ -1246,41 +1273,14 @@ impl Concatenate for NumericArray {
to: "NumericArray",
message: Some(format!(
"Cannot concatenate mismatched NumericArray variants: {:?} and {:?}",
variant_name(&lhs),
variant_name(&rhs)
lhs.variant_name(),
rhs.variant_name()
)),
}),
}
}
}

/// Helper function to get the variant name for error messages
fn variant_name(arr: &NumericArray) -> &'static str {
match arr {
#[cfg(feature = "extended_numeric_types")]
NumericArray::Int8(_) => "Int8",
#[cfg(feature = "extended_numeric_types")]
NumericArray::Int16(_) => "Int16",
NumericArray::Int32(_) => "Int32",
NumericArray::Int64(_) => "Int64",
#[cfg(feature = "extended_numeric_types")]
NumericArray::UInt8(_) => "UInt8",
#[cfg(feature = "extended_numeric_types")]
NumericArray::UInt16(_) => "UInt16",
NumericArray::UInt32(_) => "UInt32",
NumericArray::UInt64(_) => "UInt64",
NumericArray::Float32(_) => "Float32",
NumericArray::Float64(_) => "Float64",
#[cfg(feature = "decimal")]
NumericArray::Decimal32(_) => "Decimal32",
#[cfg(feature = "decimal")]
NumericArray::Decimal64(_) => "Decimal64",
#[cfg(feature = "decimal")]
NumericArray::Decimal128(_) => "Decimal128",
NumericArray::Null => "Null",
}
}

// ---------------------------------------------------------------------------
// From impls - DecimalArray -> NumericArray
// ---------------------------------------------------------------------------
Expand Down
26 changes: 13 additions & 13 deletions src/enums/collections/temporal_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ pub enum TemporalArray {
}

impl TemporalArray {
/// Returns the variant name as a short string, for example "Datetime64".
pub fn variant_name(&self) -> &'static str {
match self {
TemporalArray::Datetime32(_) => "Datetime32",
TemporalArray::Datetime64(_) => "Datetime64",
TemporalArray::Null => "Null",
}
}

/// Returns the logical length of the temporal array.
#[inline]
pub fn len(&self) -> usize {
Expand Down Expand Up @@ -225,8 +234,8 @@ impl TemporalArray {
to: "TemporalArray",
message: Some(format!(
"Cannot insert {} into {}: incompatible types",
temporal_variant_name(rhs),
temporal_variant_name(lhs)
rhs.variant_name(),
lhs.variant_name()
)),
}),
}
Expand Down Expand Up @@ -327,8 +336,8 @@ impl Concatenate for TemporalArray {
to: "TemporalArray",
message: Some(format!(
"Cannot concatenate mismatched TemporalArray variants: {:?} and {:?}",
temporal_variant_name(&lhs),
temporal_variant_name(&rhs)
lhs.variant_name(),
rhs.variant_name()
)),
}),
}
Expand Down Expand Up @@ -672,15 +681,6 @@ impl DatetimeOps for TemporalArray {
}
}

/// Helper function to get the variant name for error messages
fn temporal_variant_name(arr: &TemporalArray) -> &'static str {
match arr {
TemporalArray::Datetime32(_) => "Datetime32",
TemporalArray::Datetime64(_) => "Datetime64",
TemporalArray::Null => "Null",
}
}

impl Display for TemporalArray {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
45 changes: 23 additions & 22 deletions src/enums/collections/text_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ pub enum TextArray {
}

impl TextArray {
/// Returns the variant name as a short string, for example "String32" or "Categorical8".
pub fn variant_name(&self) -> &'static str {
match self {
TextArray::String32(_) => "String32",
#[cfg(feature = "large_string")]
TextArray::String64(_) => "String64",
#[cfg(feature = "default_categorical_8")]
TextArray::Categorical8(_) => "Categorical8",
#[cfg(feature = "extended_categorical")]
TextArray::Categorical16(_) => "Categorical16",
#[cfg(any(
not(feature = "default_categorical_8"),
feature = "extended_categorical"
))]
TextArray::Categorical32(_) => "Categorical32",
#[cfg(feature = "extended_categorical")]
TextArray::Categorical64(_) => "Categorical64",
TextArray::Null => "Null",
}
}

/// Returns the logical length of the text array.
#[inline]
pub fn len(&self) -> usize {
Expand Down Expand Up @@ -711,31 +732,11 @@ impl Concatenate for TextArray {
to: "TextArray",
message: Some(format!(
"Cannot concatenate mismatched TextArray variants: {:?} and {:?}",
text_variant_name(&lhs),
text_variant_name(&rhs)
lhs.variant_name(),
rhs.variant_name()
)),
}),
}
}
}

/// Helper function to get the variant name for error messages
fn text_variant_name(arr: &TextArray) -> &'static str {
match arr {
TextArray::String32(_) => "String32",
#[cfg(feature = "large_string")]
TextArray::String64(_) => "String64",
#[cfg(feature = "default_categorical_8")]
TextArray::Categorical8(_) => "Categorical8",
#[cfg(feature = "extended_categorical")]
TextArray::Categorical16(_) => "Categorical16",
#[cfg(any(
not(feature = "default_categorical_8"),
feature = "extended_categorical"
))]
TextArray::Categorical32(_) => "Categorical32",
#[cfg(feature = "extended_categorical")]
TextArray::Categorical64(_) => "Categorical64",
TextArray::Null => "Null",
}
}
Loading