Skip to content

Commit

Permalink
improve null behavior rank all nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 4, 2021
1 parent 53c1f6c commit f5a2fd6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions polars/polars-core/src/chunked_array/ops/unique/rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ pub(crate) fn rank(s: &Series, method: RankMethod) -> Series {
// impute with the maximum value possible.
// todo! maybe add + 1 at the end on the null values.
if s.has_validity() {
// if s.null_count() == s.len() {
// return match method {
// Average => Float32Chunked::full_null(s.name(), s.len()).into_series(),
// _ => UInt32Chunked::full_null(s.name(), s.len()).into_series()
// }
// }

// replace null values with the maximum value of that dtype
let s = s.fill_null(FillNullStrategy::MaxBound).unwrap();
return rank(&s, method);
Expand Down Expand Up @@ -320,4 +327,14 @@ mod test {

Ok(())
}

#[test]
fn test_rank_all_null() {
let s = UInt32Chunked::new_from_opt_slice("", &[None, None, None]).into_series();
let out = rank(&s, RankMethod::Average);
assert_eq!(out.null_count(), 3);
assert_eq!(out.dtype(), &DataType::Float32);
let out = rank(&s, RankMethod::Max);
assert_eq!(out.dtype(), &DataType::UInt32);
}
}

0 comments on commit f5a2fd6

Please sign in to comment.