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

feat: Introduce explode for ArrayNameSpace #13923

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

reswqa
Copy link
Collaborator

@reswqa reswqa commented Jan 23, 2024

No description provided.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Jan 23, 2024
@@ -101,7 +102,39 @@ impl ChunkExplode for ArrayChunked {
fn explode(&self) -> PolarsResult<Series> {
let ca = self.rechunk();
let arr = ca.downcast_iter().next().unwrap();
Ok(Series::try_from((self.name(), arr.values().clone())).unwrap())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous implementation would cause the None value to explode into multiple values(as many as arr.width):

s = pl.Series("a", [[1, 2, None]], dtype=pl.Array(pl.Int64, 3))
s.arr.explode()

shape: (5,)
        Series: 'a' [i64]
        [
            1
            2
            None
            None
            None
        ]

This behavior is somewhat unreasonable for me.

@reswqa reswqa marked this pull request as ready for review January 23, 2024 12:16
@ritchie46
Copy link
Member

Nice! I think we should also implement ExplodeAndOffsets in a later PR. Then we can explode a DataFrame by an array column.

@ritchie46 ritchie46 merged commit 3648400 into pola-rs:main Jan 24, 2024
23 checks passed
r-brink pushed a commit to r-brink/polars that referenced this pull request Jan 24, 2024
@reswqa
Copy link
Collaborator Author

reswqa commented Jan 24, 2024

I think we should also implement ExplodeAndOffsets in a later PR. Then we can explode a DataFrame by an array column.

Yes, PR is coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants