Skip to content

Commit 5084fa1

Browse files
authored
perf: Use single-key optimization with Categorical (#23436)
1 parent 0f6f68c commit 5084fa1

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

crates/polars-expr/src/groups/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ pub fn new_hash_grouper(key_schema: Arc<Schema>) -> Box<dyn Grouper> {
8787
Box::new(single_key::SingleKeyHashGrouper::<Int128Type>::new())
8888
},
8989
#[cfg(feature = "dtype-categorical")]
90-
DataType::Enum(fcats, _) => {
91-
with_match_categorical_physical_type!(fcats.physical(), |$C| {
90+
dt @ (DataType::Enum(_, _) | DataType::Categorical(_, _)) => {
91+
with_match_categorical_physical_type!(dt.cat_physical().unwrap(), |$C| {
9292
Box::new(single_key::SingleKeyHashGrouper::<<$C as PolarsCategoricalType>::PolarsPhysical>::new())
9393
})
9494
},

crates/polars-expr/src/hash_keys.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn hash_keys_variant_for_dtype(dt: &DataType) -> HashKeysVariant {
2929
#[cfg(feature = "dtype-decimal")]
3030
DataType::Decimal(_, _) => HashKeysVariant::Single,
3131
#[cfg(feature = "dtype-categorical")]
32-
DataType::Enum(_, _) => HashKeysVariant::Single,
32+
DataType::Enum(_, _) | DataType::Categorical(_, _) => HashKeysVariant::Single,
3333

3434
DataType::String | DataType::Binary => HashKeysVariant::Binview,
3535

@@ -76,8 +76,8 @@ macro_rules! downcast_single_key_ca {
7676
#[cfg(feature = "dtype-decimal")]
7777
DataType::Decimal(..) => { let $ca = $self.decimal().unwrap().physical(); $($body)* },
7878
#[cfg(feature = "dtype-categorical")]
79-
DataType::Enum(fcats, _) => {
80-
match fcats.physical() {
79+
dt @ (DataType::Enum(_, _) | DataType::Categorical(_, _)) => {
80+
match dt.cat_physical().unwrap() {
8181
CategoricalPhysical::U8 => { let $ca = $self.cat8().unwrap().physical(); $($body)* },
8282
CategoricalPhysical::U16 => { let $ca = $self.cat16().unwrap().physical(); $($body)* },
8383
CategoricalPhysical::U32 => { let $ca = $self.cat32().unwrap().physical(); $($body)* },

crates/polars-expr/src/hot_groups/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ pub fn new_hash_hot_grouper(key_schema: Arc<Schema>, num_groups: usize) -> Box<d
8282
#[cfg(feature = "dtype-decimal")]
8383
DataType::Decimal(_, _) => Box::new(SK::<Int128Type>::new(dt, ng)),
8484
#[cfg(feature = "dtype-categorical")]
85-
DataType::Enum(ref fcats, _) => {
86-
with_match_categorical_physical_type!(fcats.physical(), |$C| {
85+
dt @ (DataType::Enum(_, _) | DataType::Categorical(_, _)) => {
86+
with_match_categorical_physical_type!(dt.cat_physical().unwrap(), |$C| {
8787
Box::new(SK::<<$C as PolarsCategoricalType>::PolarsPhysical>::new(dt.clone(), ng))
8888
})
8989
},

crates/polars-expr/src/idx_table/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ pub fn new_idx_table(key_schema: Arc<Schema>) -> Box<dyn IdxTable> {
104104
#[cfg(feature = "dtype-decimal")]
105105
DataType::Decimal(_, _) => Box::new(SKIT::<Int128Type>::new()),
106106
#[cfg(feature = "dtype-categorical")]
107-
DataType::Enum(fcats, _) => {
108-
with_match_categorical_physical_type!(fcats.physical(), |$C| {
107+
dt @ (DataType::Enum(_, _) | DataType::Categorical(_, _)) => {
108+
with_match_categorical_physical_type!(dt.cat_physical().unwrap(), |$C| {
109109
Box::new(SKIT::<<$C as PolarsCategoricalType>::PolarsPhysical>::new())
110110
})
111111
},

0 commit comments

Comments
 (0)