Skip to content

Commit

Permalink
feature gate take_from_iter; closes #1038
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 26, 2021
1 parent f44a9cc commit c300ef3
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 24 deletions.
5 changes: 4 additions & 1 deletion polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ row_hash = ["polars-core/row_hash"]
reinterpret = ["polars-core/reinterpret", "polars-core/dtype-u64"]
decompress = ["polars-io/decompress"]
mode = ["polars-core/mode", "polars-lazy/mode"]
take_opt_iter = ["polars-core/take_opt_iter"]
extract_jsonpath = ["polars-core/extract_jsonpath", "polars-core/strings"]

# don't use this
Expand Down Expand Up @@ -146,7 +147,9 @@ docs-selection = [
"cross_join",
"concat_str",
"decompress",
"mode"
"mode",
"take_opt_iter",
"extract_jsonpath"
]

[dependencies]
Expand Down
4 changes: 3 additions & 1 deletion polars/polars-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dot_product = []
concat_str = []
row_hash = []
reinterpret = []
take_opt_iter = []
mode = []
extract_jsonpath = ["serde_json", "jsonpath_lib"]

Expand Down Expand Up @@ -102,7 +103,8 @@ docs-selection = [
"dot_product",
"concat_str",
"row_hash",
"mode"
"mode",
"extract_jsonpath"
]

[dependencies]
Expand Down
12 changes: 2 additions & 10 deletions polars/polars-core/src/chunked_array/ops/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,16 +673,8 @@ impl<T: PolarsObject> ChunkTake for ObjectChunked<T> {
ca.rename(self.name());
Ok(ca)
}
TakeIdx::IterNulls(iter) => {
handle_empty_array_take_iter!(self, Self);
let taker = self.take_rand();

let mut ca: ObjectChunked<T> = iter
.map(|opt_idx| opt_idx.and_then(|idx| taker.get(idx).cloned()))
.collect();

ca.rename(self.name());
Ok(ca)
TakeIdx::IterNulls(_) => {
panic!("not supported in take, only supported in take_unchecked for the join operation")
}
}
}
Expand Down
1 change: 1 addition & 0 deletions polars/polars-core/src/series/implementations/dates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ macro_rules! impl_dyn_series {
physical_dispatch!(self, take_opt_iter_unchecked, iter)
}

#[cfg(feature = "take_opt_iter")]
fn take_opt_iter(
&self,
iter: &mut dyn Iterator<Item = Option<usize>>,
Expand Down
1 change: 1 addition & 0 deletions polars/polars-core/src/series/implementations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ macro_rules! impl_dyn_series {
ChunkTake::take_unchecked(&self.0, SeriesWrap(iter).into()).into_series()
}

#[cfg(feature = "take_opt_iter")]
fn take_opt_iter(
&self,
iter: &mut dyn Iterator<Item = Option<usize>>,
Expand Down
1 change: 1 addition & 0 deletions polars/polars-core/src/series/implementations/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ where
ChunkTake::take_unchecked(&self.0, SeriesWrap(iter).into()).into_series()
}

#[cfg(feature = "take_opt_iter")]
fn take_opt_iter(&self, _iter: &mut dyn Iterator<Item = Option<usize>>) -> Result<Series> {
todo!()
}
Expand Down
14 changes: 2 additions & 12 deletions polars/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,6 @@ pub trait SeriesTrait:
}

/// Take by index from an iterator. This operation clones the data.
///
/// # Safety
///
/// Out of bounds access doesn't Error but will return a Null value for that element.
fn take_iter(&self, _iter: &mut dyn Iterator<Item = usize>) -> Result<Series> {
unimplemented!()
}
Expand Down Expand Up @@ -496,19 +492,13 @@ pub trait SeriesTrait:
}

/// Take by index from an iterator. This operation clones the data.
///
/// # Safety
///
/// Out of bounds access doesn't Error but will return a Null value for that element
#[cfg(feature = "take_opt_iter")]
#[cfg_attr(docsrs, doc(cfg(feature = "take_opt_iter")))]
fn take_opt_iter(&self, _iter: &mut dyn Iterator<Item = Option<usize>>) -> Result<Series> {
unimplemented!()
}

/// Take by index. This operation is clone.
///
/// # Safety
///
/// Out of bounds access doesn't Error but will return a Null value for that element.
fn take(&self, _indices: &UInt32Chunked) -> Result<Series> {
unimplemented!()
}
Expand Down
3 changes: 3 additions & 0 deletions polars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
//! - `dot_product` - Dot/inner product on Series and Expressions.
//! - `concat_str` - Concat string data in linear time.
//! - `reinterpret` - Utility to reinterpret bits to signed/unsigned
//! - `take_opt_iter` - Take from a Series with `Iterator<Item=Option<usize>>`
//! - `mode` - [Return the most occurring value(s)](crate::chunked_array::ops::ChunkUnique::mode)
//! - `extract_jsonpath` - [Run jsonpath queries on Utf8Chunked](https://goessner.net/articles/JsonPath/)
//! * `DataFrame` pretty printing (Choose one or none, but not both):
//! - `plain_fmt` - no overflowing (less compilation times)
//! - `pretty_fmt` - cell overflow (increased compilation times)
Expand Down

0 comments on commit c300ef3

Please sign in to comment.