Skip to content

Commit

Permalink
Merge branch 'pola-rs:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ggggggggg authored Aug 2, 2024
2 parents 40f8b1b + 618a710 commit f4d5ba5
Show file tree
Hide file tree
Showing 21 changed files with 417 additions and 152 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions crates/polars-arrow/src/array/binview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,29 @@ impl<T: ViewType + ?Sized> BinaryViewArrayGeneric<T> {
)
}

/// Apply a function over the views. This can be used to update views in operations like slicing.
///
/// # Safety
/// Update the views. All invariants of the views apply.
pub unsafe fn apply_views<F: FnMut(View, &T) -> View>(&self, mut update_view: F) -> Self {
let arr = self.clone();
let (views, buffers, validity, total_bytes_len, total_buffer_len) = arr.into_inner();

let mut views = views.make_mut();
for v in views.iter_mut() {
let str_slice = T::from_bytes_unchecked(v.get_slice_unchecked(&buffers));
*v = update_view(*v, str_slice);
}
Self::new_unchecked(
self.data_type.clone(),
views.into(),
buffers,
validity,
total_bytes_len,
total_buffer_len,
)
}

pub fn try_new(
data_type: ArrowDataType,
views: Buffer<View>,
Expand Down
12 changes: 12 additions & 0 deletions crates/polars-core/src/chunked_array/ops/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,15 @@ where
});
}
}

impl StringChunked {
/// # Safety
/// Update the views. All invariants of the views apply.
pub unsafe fn apply_views<F: FnMut(View, &str) -> View + Copy>(&self, update_view: F) -> Self {
let mut out = self.clone();
for arr in out.downcast_iter_mut() {
*arr = arr.apply_views(update_view);
}
out
}
}
13 changes: 4 additions & 9 deletions crates/polars-lazy/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,9 @@ impl LazyFrame {
fn _drop<I, T>(self, columns: I, strict: bool) -> Self
where
I: IntoIterator<Item = T>,
T: AsRef<str>,
T: Into<Selector>,
{
let to_drop = columns
.into_iter()
.map(|s| s.as_ref().to_string())
.collect::<PlHashSet<_>>();
let to_drop = columns.into_iter().map(|c| c.into()).collect();

let opt_state = self.get_opt_state();
let lp = self.get_plan_builder().drop(to_drop, strict).build();
Expand All @@ -444,11 +441,10 @@ impl LazyFrame {
///
/// Any given columns that are not in the schema will give a [`PolarsError::ColumnNotFound`]
/// error while materializing the [`LazyFrame`].
#[inline]
pub fn drop<I, T>(self, columns: I) -> Self
where
I: IntoIterator<Item = T>,
T: AsRef<str>,
T: Into<Selector>,
{
self._drop(columns, true)
}
Expand All @@ -458,11 +454,10 @@ impl LazyFrame {
/// and let the projection pushdown optimize away the unneeded columns.
///
/// If a column name does not exist in the schema, it will quietly be ignored.
#[inline]
pub fn drop_no_validate<I, T>(self, columns: I) -> Self
where
I: IntoIterator<Item = T>,
T: AsRef<str>,
T: Into<Selector>,
{
self._drop(columns, false)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-ops/src/chunked_array/strings/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ pub trait StringNameSpaceImpl: AsString {
let ca = self.as_string();
let n = n.strict_cast(&DataType::Int64)?;

Ok(substring::head(ca, n.i64()?))
substring::head(ca, n.i64()?)
}

/// Slice the last `n` values of the string.
Expand All @@ -633,7 +633,7 @@ pub trait StringNameSpaceImpl: AsString {
let ca = self.as_string();
let n = n.strict_cast(&DataType::Int64)?;

Ok(substring::tail(ca, n.i64()?))
substring::tail(ca, n.i64()?)
}
}

Expand Down
Loading

0 comments on commit f4d5ba5

Please sign in to comment.