Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for arrays.
Browse files Browse the repository at this point in the history
pythonspeed committed Oct 17, 2024
1 parent c0c30ed commit 47ac42f
Showing 3 changed files with 25 additions and 2 deletions.
12 changes: 12 additions & 0 deletions crates/polars-core/src/chunked_array/ops/search.rs
Original file line number Diff line number Diff line change
@@ -29,3 +29,15 @@ impl ChunkSearch<'_, &Series> for ListChunked {
})
}
}

#[cfg(feature="dtype-array")]
impl ChunkSearch<'_, &Series> for ArrayChunked {
fn index_of(&self, value: Option<&Series>) -> Option<usize> {
self.amortized_iter()
.position(|opt_val| match (opt_val, value) {
(Some(in_series), Some(value)) => in_series.as_ref() == value,
(None, None) => true,
_ => false,
})
}
}
9 changes: 9 additions & 0 deletions crates/polars-python/src/series/scatter.rs
Original file line number Diff line number Diff line change
@@ -199,6 +199,15 @@ fn index_of(series: &Series, value_series: &Series) -> PolarsResult<Option<usize
.map(|arr| Series::from_arrow("".into(), arr).unwrap());
Ok(series.list()?.index_of(value.as_ref()))
},
#[cfg(feature="dtype-array")]
DataType::Array(_, _) => {
let value = value_series
.array()
.unwrap()
.get(0)
.map(|arr| Series::from_arrow("".into(), arr).unwrap());
Ok(series.array()?.index_of(value.as_ref()))
},
_ => unimplemented!("TODO"),
}
}
6 changes: 4 additions & 2 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
@@ -4749,12 +4749,14 @@ def index_of(
TODO
"""
if isinstance(value, Series):
# Searching for lists...
# TODO what about searching for arrays?
# Searching for lists or arrays:
value = value.implode()
else:
value = Series(values=[value])

if isinstance(self.dtype, Array):
value = value.cast(Array(self.dtype.inner, len(value[0])))

return self._s.index_of(value._s)

def clear(self, n: int = 0) -> Series:

0 comments on commit 47ac42f

Please sign in to comment.