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: Expressify list.shift #11320

Merged
merged 2 commits into from
Sep 27, 2023
Merged

feat: Expressify list.shift #11320

merged 2 commits into from
Sep 27, 2023

Conversation

reswqa
Copy link
Collaborator

@reswqa reswqa commented Sep 26, 2023

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 Sep 26, 2023
@@ -188,6 +188,47 @@ impl ListChunked {
unsafe { self.amortized_iter().for_each(f) }
}

/// Zip with a `ChunkedArray` then apply a binary function `F` elementwise.
#[must_use]
pub fn zip_and_apply_amortized<'a, T, I, F>(&'a self, ca: &'a ChunkedArray<T>, mut f: F) -> Self
Copy link
Collaborator Author

@reswqa reswqa Sep 26, 2023

Choose a reason for hiding this comment

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

I don't know what name would be more appropriate, but I assume that having a safe version would be good.

@reswqa reswqa marked this pull request as ready for review September 27, 2023 02:29
_ => out,
}
})
.collect_trusted()
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make this a bit more resilient to ambiguous dtypes. We can use collect_ca_trusted_with_dtype and accept the list inner type as argument of this function and then construct the DataType::List<inner> with that.

In a later PR we can do the same with apply_amortized.

Copy link
Collaborator Author

@reswqa reswqa Sep 27, 2023

Choose a reason for hiding this comment

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

pub fn zip_and_apply_amortized<'a, T, I, F>(&'a self, ca: &'a ChunkedArray<T>, mut f: F) -> Self

This function will return Self, maybe we don't need accept an inner type as argument, but pass self.dtype().clone() to collect_ca_trusted_with_dtype directly? What do you think?

In a later PR we can do the same with apply_amortized.

I tend do this for apply_amortized also in this PR, after that, I think we can remove the call to Ok(self.same_type(out)) in lst_shift safely.

Copy link
Member

Choose a reason for hiding this comment

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

This function will return Self, maybe we don't need accept an inner type as argument, but pass self.dtype().clone() to collect_ca_trusted_with_dtype directly? What do you think?

Yes, that would be sufficient.

Copy link
Collaborator Author

@reswqa reswqa Sep 27, 2023

Choose a reason for hiding this comment

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

A bad news: It seems that our implementation of collect_ca_trusted_with_dtype will forward to collect_arr_trusted_with_dtype and just wrap this single Array to ChunkedArray.

So it requires ArrayFromIterDtype of Option<Series> or Series for ListArray(Because the closure of apply_amortized is F: FnMut(UnstableSeries<'a>) -> Series), but we don't have this(Perhaps we don't want to implement it either, after all, Series may contain multiple arrays if not re-chunk).

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's leave it for now. Maybe we can take a look later. Want to have this in the release. :)

@ritchie46 ritchie46 merged commit 55c6694 into pola-rs:main Sep 27, 2023
25 checks passed
romanovacca pushed a commit to romanovacca/polars that referenced this pull request Oct 1, 2023
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