Skip to content

Commit

Permalink
More explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonspeed committed Jan 15, 2025
1 parent 3083803 commit 9fc4d5f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/polars-ops/src/chunked_array/list/index_of_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ pub fn list_index_of_in(ca: &ListChunked, needles: &Series) -> PolarsResult<Seri
);
ca.amortized_iter().for_each(|opt_series| {
if let Some(subseries) = opt_series {
// TODO justify why unwrap()s are ok
builder.append_option(
// TODO clone() sucks, maybe need to change the API for index_of?
// TODO clone() sucks, maybe need to change the API for
// index_of so it takes AnyValue<'_> instead of a Scalar
// which implies AnyValue<'static>?
index_of(subseries.as_ref(), needle.clone())
.unwrap()
.map(|v| v.try_into().unwrap()),
Expand All @@ -29,13 +30,17 @@ pub fn list_index_of_in(ca: &ListChunked, needles: &Series) -> PolarsResult<Seri
});
} else {
ca.amortized_iter()
// TODO iter() assumes a single chunk. could continue to use this
// and just rechunk(), or have needles also be a ChunkedArray, in
// which case we'd need to have to use one of the
// dispatch-on-dtype-and-cast-to-relevant-chunkedarray-type macros
// to duplicate the implementation code per dtype.
.zip(needles.iter())
.for_each(|(opt_series, needle)| {
match (opt_series, needle) {
(None, _) => builder.append_null(),
(Some(subseries), needle) => {
let needle = Scalar::new(needles.dtype().clone(), needle.into_static());
// TODO justify why unwrap()s are ok
builder.append_option(
index_of(subseries.as_ref(), needle)
.unwrap()
Expand Down

0 comments on commit 9fc4d5f

Please sign in to comment.