Skip to content

Commit

Permalink
fix: Fix boolean distinct (#16765)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Jun 6, 2024
1 parent 27abc9d commit 5a0c803
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions crates/polars-compute/src/distinct_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ impl DistinctCountKernel for BooleanArray {
return 0;
}

let unset_bits = self.values().unset_bits();
2 - usize::from(unset_bits == 0 || unset_bits == self.values().len())
if self.null_count() == 0 {
let unset_bits = self.values().unset_bits();
2 - usize::from(unset_bits == 0 || unset_bits == self.values().len())
} else {
let values = self.values() & self.validity().unwrap();
let unset_bits = self.values().unset_bits();
3 - usize::from(unset_bits == 0 || unset_bits == values.len())
}
}
}
6 changes: 5 additions & 1 deletion crates/polars-parquet/src/arrow/write/boolean/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ pub(super) fn build_statistics(
null_count: options.null_count.then(|| array.null_count() as i64),
distinct_count: options
.distinct_count
.then(|| array.distinct_count().try_into().ok())
.then(|| {
(array.distinct_count() - ((array.null_count() > 0) as usize))
.try_into()
.ok()
})
.flatten(),
max_value: options
.max_value
Expand Down

0 comments on commit 5a0c803

Please sign in to comment.