diff --git a/crates/polars-core/src/frame/group_by/into_groups.rs b/crates/polars-core/src/frame/group_by/into_groups.rs index 486e503999a4..fe2fd5a493e5 100644 --- a/crates/polars-core/src/frame/group_by/into_groups.rs +++ b/crates/polars-core/src/frame/group_by/into_groups.rs @@ -185,6 +185,14 @@ where }; num_groups_proxy(ca, multithreaded, sorted) }, + #[cfg(feature = "dtype-decimal")] + DataType::Decimal(_, _) => { + // convince the compiler that we are this type. + let ca: &Int128Chunked = unsafe { + &*(self as *const ChunkedArray as *const ChunkedArray) + }; + num_groups_proxy(ca, multithreaded, sorted) + }, #[cfg(all(feature = "performant", feature = "dtype-i8", feature = "dtype-u8"))] DataType::Int8 => { // convince the compiler that we are this type. diff --git a/crates/polars-core/src/series/implementations/decimal.rs b/crates/polars-core/src/series/implementations/decimal.rs index 5b5bdc5fe6b9..a72569408b36 100644 --- a/crates/polars-core/src/series/implementations/decimal.rs +++ b/crates/polars-core/src/series/implementations/decimal.rs @@ -119,6 +119,10 @@ impl private::PrivateSeries for SeriesWrap { let rhs = rhs.decimal()?; ((&self.0) / rhs).map(|ca| ca.into_series()) } + #[cfg(feature = "algorithm_group_by")] + fn group_tuples(&self, multithreaded: bool, sorted: bool) -> PolarsResult { + self.0.group_tuples(multithreaded, sorted) + } } impl SeriesTrait for SeriesWrap { diff --git a/crates/polars-utils/src/hashing.rs b/crates/polars-utils/src/hashing.rs index c00f05e6cc73..12e59bf52f26 100644 --- a/crates/polars-utils/src/hashing.rs +++ b/crates/polars-utils/src/hashing.rs @@ -86,6 +86,14 @@ impl_hash_partition_as_u64!(i16); impl_hash_partition_as_u64!(i32); impl_hash_partition_as_u64!(i64); +impl DirtyHash for i128 { + fn dirty_hash(&self) -> u64 { + (*self as u64) + .wrapping_mul(RANDOM_ODD) + .wrapping_add((*self >> 64) as u64) + } +} + impl<'a> DirtyHash for BytesHash<'a> { fn dirty_hash(&self) -> u64 { self.hash diff --git a/crates/polars/tests/it/lazy/group_by.rs b/crates/polars/tests/it/lazy/group_by.rs index 4e24e1d24fa8..d8e20c804ca0 100644 --- a/crates/polars/tests/it/lazy/group_by.rs +++ b/crates/polars/tests/it/lazy/group_by.rs @@ -126,18 +126,19 @@ fn test_group_by_agg_list_with_not_aggregated() -> PolarsResult<()> { } #[test] -#[cfg(all(feature = "dtype-duration", feature = "dtype-struct"))] +#[cfg(all(feature = "dtype-duration", feature = "dtype-decimal"))] fn test_logical_mean_partitioned_group_by_block() -> PolarsResult<()> { let _guard = SINGLE_LOCK.lock(); let df = df![ - "a" => [1, 1, 2], + "decimal" => [1, 1, 2], "duration" => [1000, 2000, 3000] ]?; let out = df .lazy() + .with_column(col("decimal").cast(DataType::Decimal(None, Some(2)))) .with_column(col("duration").cast(DataType::Duration(TimeUnit::Microseconds))) - .group_by([col("a")]) + .group_by([col("decimal")]) .agg([col("duration").mean()]) .sort("duration", Default::default()) .collect()?;