This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 068a7e44f0 Add `DataType::is_decimal` (#9100)
068a7e44f0 is described below

commit 068a7e44f0881ffe542225c5dd8cb354b74a9615
Author: Adam Gutglick <[email protected]>
AuthorDate: Tue Jan 6 21:53:24 2026 +0000

    Add `DataType::is_decimal` (#9100)
    
    # Which issue does this PR close?
    
    - Closes #5163
    
    # Rationale for this change
    
    I've implemented this function at least twice in other codebases, and
    `arrow-rs` now has 4 variants.
    
    # What changes are included in this PR?
    
    New public function to test if a `DataType` is any decimal variant.
    
    # Are these changes tested?
    
    Yes
    
    # Are there any user-facing changes?
    
    New function including docs.
---
 arrow-schema/src/datatype.rs | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs
index e3f67e6ac0..40c28649c2 100644
--- a/arrow-schema/src/datatype.rs
+++ b/arrow-schema/src/datatype.rs
@@ -591,6 +591,16 @@ impl DataType {
         matches!(self, UInt8 | UInt16 | UInt32 | UInt64)
     }
 
+    /// Returns true if this type is decimal: (Decimal*).
+    #[inline]
+    pub fn is_decimal(&self) -> bool {
+        use DataType::*;
+        matches!(
+            self,
+            Decimal32(..) | Decimal64(..) | Decimal128(..) | Decimal256(..)
+        )
+    }
+
     /// Returns true if this type is valid as a dictionary key
     #[inline]
     pub fn is_dictionary_key_type(&self) -> bool {
@@ -1168,6 +1178,15 @@ mod tests {
         assert!(!DataType::is_floating(&DataType::Int32));
     }
 
+    #[test]
+    fn test_decimal() {
+        assert!(DataType::is_decimal(&DataType::Decimal32(4, 2)));
+        assert!(DataType::is_decimal(&DataType::Decimal64(4, 2)));
+        assert!(DataType::is_decimal(&DataType::Decimal128(4, 2)));
+        assert!(DataType::is_decimal(&DataType::Decimal256(4, 2)));
+        assert!(!DataType::is_decimal(&DataType::Float16));
+    }
+
     #[test]
     fn test_datatype_is_null() {
         assert!(DataType::is_null(&DataType::Null));

Reply via email to