Skip to content

Commit

Permalink
fix rank empty schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 5, 2021
1 parent ae2aad5 commit 2091863
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions polars/polars-core/src/chunked_array/ops/unique/rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ pub enum RankMethod {
}

pub(crate) fn rank(s: &Series, method: RankMethod) -> Series {
if s.len() == 1 {
return match method {
Average => Series::new(s.name(), &[1.0f32]),
_ => Series::new(s.name(), &[1u32]),
};
match s.len() {
1 => {
return match method {
Average => Series::new(s.name(), &[1.0f32]),
_ => Series::new(s.name(), &[1u32]),
};
}
0 => {
return match method {
Average => Float32Chunked::new_from_slice(s.name(), &[]).into_series(),
_ => UInt32Chunked::new_from_slice(s.name(), &[]).into_series(),
}
}
_ => {}
}
// don't fully understand how to deal with nulls yet
// impute with the maximum value possible.
Expand Down Expand Up @@ -337,4 +346,12 @@ mod test {
let out = rank(&s, RankMethod::Max);
assert_eq!(out.dtype(), &DataType::UInt32);
}
#[test]
fn test_rank_empty() {
let s = UInt32Chunked::new_from_slice("", &[]).into_series();
let out = rank(&s, RankMethod::Average);
assert_eq!(out.dtype(), &DataType::Float32);
let out = rank(&s, RankMethod::Max);
assert_eq!(out.dtype(), &DataType::UInt32);
}
}

0 comments on commit 2091863

Please sign in to comment.