Path: blob/main/crates/polars-arrow/src/scalar/dictionary.rs
6939 views
use std::any::Any;12use super::Scalar;3use crate::array::*;4use crate::datatypes::ArrowDataType;56/// The [`DictionaryArray`] equivalent of [`Array`] for [`Scalar`].7#[derive(Debug, Clone)]8pub struct DictionaryScalar<K: DictionaryKey> {9value: Option<Box<dyn Scalar>>,10phantom: std::marker::PhantomData<K>,11dtype: ArrowDataType,12}1314impl<K: DictionaryKey> PartialEq for DictionaryScalar<K> {15fn eq(&self, other: &Self) -> bool {16(self.dtype == other.dtype) && (self.value.as_ref() == other.value.as_ref())17}18}1920impl<K: DictionaryKey> DictionaryScalar<K> {21/// returns a new [`DictionaryScalar`]22/// # Panics23/// iff24/// * the `dtype` is not `List` or `LargeList` (depending on this scalar's offset `O`)25/// * the child of the `dtype` is not equal to the `values`26#[inline]27pub fn new(dtype: ArrowDataType, value: Option<Box<dyn Scalar>>) -> Self {28Self {29value,30phantom: std::marker::PhantomData,31dtype,32}33}3435/// The values of the [`DictionaryScalar`]36pub fn value(&self) -> Option<&Box<dyn Scalar>> {37self.value.as_ref()38}39}4041impl<K: DictionaryKey> Scalar for DictionaryScalar<K> {42fn as_any(&self) -> &dyn Any {43self44}4546fn is_valid(&self) -> bool {47self.value.is_some()48}4950fn dtype(&self) -> &ArrowDataType {51&self.dtype52}53}545556