Skip to content

Commit

Permalink
categorical aggregation output consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 20, 2021
1 parent fec76cf commit cd81f5e
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 35 deletions.
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/ops/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ impl VarAggSeries for BooleanChunked {
#[cfg(feature = "dtype-categorical")]
impl VarAggSeries for CategoricalChunked {
fn var_as_series(&self) -> Series {
self.cast::<UInt32Type>().unwrap().var_as_series()
unimplemented!()
}

fn std_as_series(&self) -> Series {
self.cast::<UInt32Type>().unwrap().std_as_series()
unimplemented!()
}
}
impl VarAggSeries for ListChunked {
Expand Down
11 changes: 11 additions & 0 deletions polars/polars-core/src/chunked_array/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,17 @@ impl ChunkFullNull for ListChunked {
}
}

#[cfg(feature = "dtype-categorical")]
impl ChunkFullNull for CategoricalChunked {
fn full_null(name: &str, length: usize) -> CategoricalChunked {
use crate::chunked_array::builder::CategoricalChunkedBuilder;
let mut builder = CategoricalChunkedBuilder::new(name, length);
let iter = (0..length).map(|_| None);
builder.from_iter(iter);
builder.finish()
}
}

impl ListChunked {
fn full_null_with_dtype(name: &str, length: usize, dt: &DataType) -> ListChunked {
let mut builder = get_list_builder(dt, 0, length, name);
Expand Down
4 changes: 1 addition & 3 deletions polars/polars-core/src/chunked_array/ops/unique/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ impl ChunkUnique<CategoricalType> for CategoricalChunked {
}
#[cfg(feature = "mode")]
fn mode(&self) -> Result<Self> {
let mut ca = self.cast::<UInt32Type>()?.mode()?;
ca.categorical_map = self.categorical_map.clone();
ca.cast()
Ok(ChunkFullNull::full_null(self.name(), 1))
}
}

Expand Down

0 comments on commit cd81f5e

Please sign in to comment.