-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] adding floor function (#1960)
Adding `floor` function. Resolves - #1910
- Loading branch information
Showing
15 changed files
with
152 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use num_traits::Float; | ||
|
||
use crate::{ | ||
array::DataArray, | ||
datatypes::{DaftFloatType, DaftNumericType}, | ||
}; | ||
|
||
use common_error::DaftResult; | ||
|
||
impl<T: DaftFloatType> DataArray<T> | ||
where | ||
T: DaftNumericType, | ||
T::Native: Float, | ||
{ | ||
pub fn floor(&self) -> DaftResult<Self> { | ||
self.apply(|v| v.floor()) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ mod count; | |
mod date; | ||
mod filter; | ||
mod float; | ||
mod floor; | ||
pub mod from_arrow; | ||
pub mod full; | ||
mod get; | ||
|
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,20 @@ | ||
use crate::datatypes::DataType; | ||
use crate::series::Series; | ||
use common_error::DaftError; | ||
use common_error::DaftResult; | ||
|
||
impl Series { | ||
pub fn floor(&self) -> DaftResult<Series> { | ||
use crate::series::array_impl::IntoSeries; | ||
use DataType::*; | ||
match self.data_type() { | ||
Int8 | Int16 | Int32 | Int64 | UInt8 | UInt16 | UInt32 | UInt64 => Ok(self.clone()), | ||
Float32 => Ok(self.f32().unwrap().floor()?.into_series()), | ||
Float64 => Ok(self.f64().unwrap().floor()?.into_series()), | ||
dt => Err(DaftError::TypeError(format!( | ||
"floor not implemented for {}", | ||
dt | ||
))), | ||
} | ||
} | ||
} |
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,40 @@ | ||
use common_error::{DaftError, DaftResult}; | ||
use daft_core::{datatypes::Field, schema::Schema, series::Series}; | ||
|
||
use super::super::FunctionEvaluator; | ||
use crate::Expr; | ||
|
||
pub(super) struct FloorEvaluator {} | ||
|
||
impl FunctionEvaluator for FloorEvaluator { | ||
fn fn_name(&self) -> &'static str { | ||
"floor" | ||
} | ||
|
||
fn to_field(&self, inputs: &[Expr], schema: &Schema, _: &Expr) -> DaftResult<Field> { | ||
if inputs.len() != 1 { | ||
return Err(DaftError::SchemaMismatch(format!( | ||
"Expected 1 input arg, got {}", | ||
inputs.len() | ||
))); | ||
} | ||
let field = inputs.first().unwrap().to_field(schema)?; | ||
if !field.dtype.is_numeric() { | ||
return Err(DaftError::TypeError(format!( | ||
"Expected input to floor to be numeric, got {}", | ||
field.dtype | ||
))); | ||
} | ||
Ok(field) | ||
} | ||
|
||
fn evaluate(&self, inputs: &[Series], _: &Expr) -> DaftResult<Series> { | ||
if inputs.len() != 1 { | ||
return Err(DaftError::SchemaMismatch(format!( | ||
"Expected 1 input arg, got {}", | ||
inputs.len() | ||
))); | ||
} | ||
inputs.first().unwrap().floor() | ||
} | ||
} |
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