Skip to content

Commit

Permalink
chore(rust): move for_each to polars-ops
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa committed Oct 11, 2023
1 parent 32e3652 commit 78e4352
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
15 changes: 0 additions & 15 deletions crates/polars-core/src/chunked_array/ops/for_each.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/polars-core/src/chunked_array/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ mod explode_and_offsets;
mod extend;
mod fill_null;
mod filter;
mod for_each;
pub mod full;
pub mod gather;
#[cfg(feature = "interpolate")]
Expand Down
11 changes: 11 additions & 0 deletions crates/polars-ops/src/chunked_array/for_each.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use polars_core::prelude::*;

pub fn for_each<'a, T, F>(ca: &'a ChunkedArray<T>, mut op: F)
where
T: PolarsDataType,
F: FnMut(Option<T::Physical<'a>>),
{
ca.downcast_iter().for_each(|arr| {
arr.iter().for_each(&mut op);
})
}
3 changes: 3 additions & 0 deletions crates/polars-ops/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ pub mod gather_skip_nulls;
#[cfg(feature = "repeat_by")]
mod repeat_by;

pub mod for_each;

pub use binary::*;
#[cfg(feature = "timezones")]
pub use datetime::*;
pub use for_each::*;
#[cfg(feature = "interpolate")]
pub use interpolate::*;
pub use list::*;
Expand Down
5 changes: 3 additions & 2 deletions crates/polars-ops/src/chunked_array/strings/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use polars_arrow::export::arrow::array::{MutableArray, MutableUtf8Array};
use polars_core::chunked_array::ops::arity::binary_elementwise_for_each;

use super::*;
use crate::prelude::for_each;

#[cfg(feature = "dtype-struct")]
pub fn split_to_struct<'a, F, I>(
Expand All @@ -21,7 +22,7 @@ where

if by.len() == 1 {
if let Some(by) = by.get(0) {
ca.for_each(|opt_s| match opt_s {
for_each(ca, |opt_s| match opt_s {
None => {
for arr in &mut arrs {
arr.push_null()
Expand Down Expand Up @@ -86,7 +87,7 @@ where
let mut builder =
ListUtf8ChunkedBuilder::new(ca.name(), ca.len(), ca.get_values_size());

ca.for_each(|opt_s| match opt_s {
for_each(ca, |opt_s| match opt_s {
Some(s) => {
let iter = op(s, by);
builder.append_values_iter(iter)
Expand Down

0 comments on commit 78e4352

Please sign in to comment.