## Coverage Report

#### Created: 2025-11-22 06:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /Users/andrewlamb/Software/datafusion/datafusion/functions/src/math/nans.rs

    Line
    Count
    Source
    1
    // Licensed to the Apache Software Foundation (ASF) under one
    2
    // or more contributor license agreements.  See the NOTICE file
    3
    // distributed with this work for additional information
    4
    // regarding copyright ownership.  The ASF licenses this file
    5
    // to you under the Apache License, Version 2.0 (the
    6
    // "License"); you may not use this file except in compliance
    7
    // with the License.  You may obtain a copy of the License at
    8
    //
    9
    //   http://www.apache.org/licenses/LICENSE-2.0
    10
    //
    11
    // Unless required by applicable law or agreed to in writing,
    12
    // software distributed under the License is distributed on an
    13
    // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14
    // KIND, either express or implied.  See the License for the
    15
    // specific language governing permissions and limitations
    16
    // under the License.
    17
    18
    //! Math function: `isnan()`.
    19
    20
    use arrow::datatypes::{DataType, Float32Type, Float64Type};
    21
    use datafusion_common::{exec_err, Result};
    22
    use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, TypeSignature};
    23
    24
    use arrow::array::{ArrayRef, AsArray, BooleanArray};
    25
    use datafusion_expr::{Documentation, ScalarUDFImpl, Signature, Volatility};
    26
    use datafusion_macros::user_doc;
    27
    use std::any::Any;
    28
    use std::sync::Arc;
    29
    30
    #[user_doc(
    31
        doc_section(label = "Math Functions"),
    32
        description = "Returns true if a given number is +NaN or -NaN otherwise returns false.",
    33
        syntax_example = "isnan(numeric_expression)",
    34
        sql_example = r#"```sql
    35
    > SELECT isnan(1);
    36
    +----------+
    37
    | isnan(1) |
    38
    +----------+
    39
    | false    |
    40
    +----------+
    41
    ```"#,
    42
        standard_argument(name = "numeric_expression", prefix = "Numeric")
    43
    )]
    44
    #[derive(Debug, PartialEq, Eq, Hash)]
    45
    pub struct IsNanFunc {
    46
        signature: Signature,
    47
    }
    48
    49
    impl Default for IsNanFunc {
    50
    0
        fn default() -> Self {
    51
    0
            Self::new()
    52
    0
        }
    53
    }
    54
    55
    impl IsNanFunc {
    56
    0
        pub fn new() -> Self {
    57
            use DataType::*;
    58
    0
            Self {
    59
    0
                signature: Signature::one_of(
    60
    0
                    vec![
    61
    0
                        TypeSignature::Exact(vec![Float32]),
    62
    0
                        TypeSignature::Exact(vec![Float64]),
    63
    0
                    ],
    64
    0
                    Volatility::Immutable,
    65
    0
                ),
    66
    0
            }
    67
    0
        }
    68
    }
    69
    70
    impl ScalarUDFImpl for IsNanFunc {
    71
    0
        fn as_any(&self) -> &dyn Any {
    72
    0
            self
    73
    0
        }
    74
    0
        fn name(&self) -> &str {
    75
    0
            "isnan"
    76
    0
        }
    77
    78
    0
        fn signature(&self) -> &Signature {
    79
    0
            &self.signature
    80
    0
        }
    81
    82
    0
        fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
    83
    0
            Ok(DataType::Boolean)
    84
    0
        }
    85
    86
    0
        fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
    87
    0
            let args = ColumnarValue::values_to_arrays(&args.args)?;
    88
    89
    0
            let arr: ArrayRef = match args[0].data_type() {
    90
    0
                DataType::Float64 => Arc::new(BooleanArray::from_unary(
    91
    0
                    args[0].as_primitive::<Float64Type>(),
    92
    0
                    f64::is_nan,
    93
    0
                )) as ArrayRef,
    94
    95
    0
                DataType::Float32 => Arc::new(BooleanArray::from_unary(
    96
    0
                    args[0].as_primitive::<Float32Type>(),
    97
    0
                    f32::is_nan,
    98
    0
                )) as ArrayRef,
    99
    0
                other => {
    100
    0
                    return exec_err!(
    101
    0
                        "Unsupported data type {other:?} for function {}",
    102
    0
                        self.name()
    103
                    )
    104
                }
    105
            };
    106
    0
            Ok(ColumnarValue::Array(arr))
    107
    0
        }
    108
    109
    0
        fn documentation(&self) -> Option<&Documentation> {
    110
    0
            self.doc()
    111
    0
        }
    112
    }