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

chore: improve From<Ca> -> Vec #14123

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions crates/polars-core/src/chunked_array/upstream_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,18 @@ where
}
}

/// From trait
impl<'a> From<&'a StringChunked> for Vec<Option<&'a str>> {
fn from(ca: &'a StringChunked) -> Self {
ca.into_iter().collect()
impl<'a, T> From<&'a ChunkedArray<T>> for Vec<Option<T::Physical<'a>>>
where
T: PolarsDataType,
{
fn from(ca: &'a ChunkedArray<T>) -> Self {
let mut out = Vec::with_capacity(ca.len());
for arr in ca.downcast_iter() {
out.extend(arr.iter())
}
out
}
}

impl From<StringChunked> for Vec<Option<String>> {
fn from(ca: StringChunked) -> Self {
ca.into_iter()
Expand All @@ -624,27 +629,17 @@ impl From<StringChunked> for Vec<Option<String>> {
}
}

impl<'a> From<&'a BooleanChunked> for Vec<Option<bool>> {
fn from(ca: &'a BooleanChunked) -> Self {
ca.into_iter().collect()
}
}

impl From<BooleanChunked> for Vec<Option<bool>> {
fn from(ca: BooleanChunked) -> Self {
ca.into_iter().collect()
}
}

impl<'a, T> From<&'a ChunkedArray<T>> for Vec<Option<T::Native>>
where
T: PolarsNumericType,
{
fn from(ca: &'a ChunkedArray<T>) -> Self {
ca.into_iter().collect()
let mut out = Vec::with_capacity(ca.len());
for arr in ca.downcast_iter() {
out.extend(arr.iter())
}
out
}
}

/// From trait
impl FromParallelIterator<Option<Series>> for ListChunked {
fn from_par_iter<I>(iter: I) -> Self
where
Expand Down
Loading