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

Adding is_null datatype shortcut method #5157

Merged
merged 1 commit into from
Dec 5, 2023
Merged
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: 18 additions & 0 deletions arrow-schema/src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,23 +350,27 @@ impl DataType {
}

/// Returns true if this type is floating: (Float*).
#[inline]
pub fn is_floating(&self) -> bool {
use DataType::*;
matches!(self, Float16 | Float32 | Float64)
}

/// Returns true if this type is integer: (Int*, UInt*).
#[inline]
pub fn is_integer(&self) -> bool {
self.is_signed_integer() || self.is_unsigned_integer()
}

/// Returns true if this type is signed integer: (Int*).
#[inline]
pub fn is_signed_integer(&self) -> bool {
use DataType::*;
matches!(self, Int8 | Int16 | Int32 | Int64)
}

/// Returns true if this type is unsigned integer: (UInt*).
#[inline]
pub fn is_unsigned_integer(&self) -> bool {
use DataType::*;
matches!(self, UInt8 | UInt16 | UInt32 | UInt64)
Expand All @@ -387,6 +391,7 @@ impl DataType {

/// Returns true if this type is nested (List, FixedSizeList, LargeList, Struct, Union,
/// or Map), or a dictionary of a nested type
#[inline]
pub fn is_nested(&self) -> bool {
use DataType::*;
match self {
Expand All @@ -398,6 +403,13 @@ impl DataType {
}
}

/// Returns true if this type is DataType::Null.
#[inline]
pub fn is_null(&self) -> bool {
use DataType::*;
matches!(self, Null)
}

/// Compares the datatype with another, ignoring nested field names
/// and metadata.
pub fn equals_datatype(&self, other: &DataType) -> bool {
Expand Down Expand Up @@ -855,6 +867,12 @@ mod tests {
assert!(!DataType::is_floating(&DataType::Int32));
}

#[test]
fn test_datatype_is_null() {
assert!(DataType::is_null(&DataType::Null));
assert!(!DataType::is_null(&DataType::Int32));
}

#[test]
fn size_should_not_regress() {
assert_eq!(std::mem::size_of::<DataType>(), 24);
Expand Down
Loading