Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Crash/incorrect group_by/n_unique on categoricals created by (q)cut #16006

Merged
merged 1 commit into from
May 2, 2024

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented May 2, 2024

Fixes #15981.

We recently added the categories upfront to make them deterministic, but we forgot to ensure that the fast unique setting was set properly:

>>> pl.Series([1]).cut([1, 2, 3])
shape: (1,)
Series: '' [cat]
[
	"(-inf, 1]"
]
>>> pl.Series([1]).cut([1, 2, 3]).n_unique()
4

As a note, it looks like CategoricalChunkedBuilder automatically sets fast unique to true by default:

pub fn finish(self) -> CategoricalChunked {
// SAFETY: keys and values are in bounds
unsafe {
CategoricalChunked::from_keys_and_values(
&self.name,
&self.cat_builder.into(),
&self.categories.into(),
self.ordering,
)
}
.with_fast_unique(true)
}

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels May 2, 2024
@nameexhaustion nameexhaustion marked this pull request as ready for review May 2, 2024 05:43
@ritchie46 ritchie46 merged commit ebd8aec into pola-rs:main May 2, 2024
25 of 27 checks passed
@nameexhaustion nameexhaustion deleted the cut branch May 2, 2024 06:32
AlexanderNenninger pushed a commit to AlexanderNenninger/polars that referenced this pull request May 3, 2024
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access violation when grouped by a categorical column
2 participants