PrimitiveScalar (scalar/primitive.rs)

polars · crates/polars-arrow/src/scalar/primitive.rs · rust · MIT
database, tag:knn-classified

Module exposing: PrimitiveScalar

// Source: https://github.com/pola-rs/polars | License: MIT | Copyright 2025 Ritchie Vink
// Provided via justclaw.it.com; keep this notice with the code.
use super::Scalar;
use crate::datatypes::ArrowDataType;
use crate::types::NativeType;

/// The implementation of [`Scalar`] for primitive, semantically equivalent to [`Option<T>`]
/// with [`ArrowDataType`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PrimitiveScalar<T: NativeType> {
    value: Option<T>,
    dtype: ArrowDataType,
}

impl<T: NativeType> PrimitiveScalar<T> {
    /// Returns a new [`PrimitiveScalar`].
    #[inline]
    pub fn new(dtype: ArrowDataType, value: Option<T>) -> Self {
        if !dtype.to_physical_type().eq_primitive(T::PRIMITIVE) {
            panic!(
                "Type {} does not support logical type

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key