-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] fill_nan and not_nan expressions (#2313)
Adds expressions for `fill_nan` and `not_nan` Todo: - add expression for `fill_na`, which is a convenience method for doing fill_null and fill_nan together, see: #571
- Loading branch information
Showing
17 changed files
with
360 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use daft_core::{ | ||
datatypes::Field, schema::Schema, series::Series, utils::supertype::try_get_supertype, | ||
}; | ||
|
||
use crate::ExprRef; | ||
|
||
use crate::functions::FunctionExpr; | ||
use common_error::{DaftError, DaftResult}; | ||
|
||
use super::super::FunctionEvaluator; | ||
|
||
pub(super) struct FillNanEvaluator {} | ||
|
||
impl FunctionEvaluator for FillNanEvaluator { | ||
fn fn_name(&self) -> &'static str { | ||
"fill_nan" | ||
} | ||
|
||
fn to_field(&self, inputs: &[ExprRef], schema: &Schema, _: &FunctionExpr) -> DaftResult<Field> { | ||
match inputs { | ||
[data, fill_value] => match (data.to_field(schema), fill_value.to_field(schema)) { | ||
(Ok(data_field), Ok(fill_value_field)) => { | ||
match (&data_field.dtype.is_floating(), &fill_value_field.dtype.is_floating(), try_get_supertype(&data_field.dtype, &fill_value_field.dtype)) { | ||
(true, true, Ok(dtype)) => Ok(Field::new(data_field.name, dtype)), | ||
_ => Err(DaftError::TypeError(format!( | ||
"Expects input to fill_nan to be float, but received {data_field} and {fill_value_field}", | ||
))), | ||
} | ||
} | ||
(Err(e), _) | (_, Err(e)) => Err(e), | ||
}, | ||
_ => Err(DaftError::SchemaMismatch(format!( | ||
"Expected 2 input args, got {}", | ||
inputs.len() | ||
))), | ||
} | ||
} | ||
|
||
fn evaluate(&self, inputs: &[Series], _: &FunctionExpr) -> DaftResult<Series> { | ||
match inputs { | ||
[data, fill_value] => data.fill_nan(fill_value), | ||
_ => Err(DaftError::ValueError(format!( | ||
"Expected 2 input args, got {}", | ||
inputs.len() | ||
))), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use daft_core::{ | ||
datatypes::{DataType, Field}, | ||
schema::Schema, | ||
series::Series, | ||
}; | ||
|
||
use crate::ExprRef; | ||
|
||
use crate::functions::FunctionExpr; | ||
use common_error::{DaftError, DaftResult}; | ||
|
||
use super::super::FunctionEvaluator; | ||
|
||
pub(super) struct NotNanEvaluator {} | ||
|
||
impl FunctionEvaluator for NotNanEvaluator { | ||
fn fn_name(&self) -> &'static str { | ||
"not_nan" | ||
} | ||
|
||
fn to_field(&self, inputs: &[ExprRef], schema: &Schema, _: &FunctionExpr) -> DaftResult<Field> { | ||
match inputs { | ||
[data] => match data.to_field(schema) { | ||
Ok(data_field) => match &data_field.dtype { | ||
// DataType::Float16 | | ||
DataType::Float32 | DataType::Float64 => { | ||
Ok(Field::new(data_field.name, DataType::Boolean)) | ||
} | ||
_ => Err(DaftError::TypeError(format!( | ||
"Expects input to is_nan to be float, but received {data_field}", | ||
))), | ||
}, | ||
Err(e) => Err(e), | ||
}, | ||
_ => Err(DaftError::SchemaMismatch(format!( | ||
"Expected 1 input args, got {}", | ||
inputs.len() | ||
))), | ||
} | ||
} | ||
|
||
fn evaluate(&self, inputs: &[Series], _: &FunctionExpr) -> DaftResult<Series> { | ||
match inputs { | ||
[data] => data.not_nan(), | ||
_ => Err(DaftError::ValueError(format!( | ||
"Expected 1 input args, got {}", | ||
inputs.len() | ||
))), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.