This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 9efaf06247 Adding `is_null` datatype shortcut method (#5157)
9efaf06247 is described below
commit 9efaf062476276570ea4c6c7b7ce698d8c2b043d
Author: comphead <[email protected]>
AuthorDate: Tue Dec 5 02:05:31 2023 -0800
Adding `is_null` datatype shortcut method (#5157)
---
arrow-schema/src/datatype.rs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs
index b78c785ae2..330ae5c9e3 100644
--- a/arrow-schema/src/datatype.rs
+++ b/arrow-schema/src/datatype.rs
@@ -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)
@@ -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 {
@@ -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 {
@@ -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);