Skip to content

Commit

Permalink
gather
Browse files Browse the repository at this point in the history
  • Loading branch information
c-peters committed Jan 26, 2024
1 parent 76350ca commit 38d2f70
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions crates/polars-core/src/chunked_array/logical/categorical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,20 +361,16 @@ impl LogicalType for CategoricalChunked {
StringChunked::with_chunk("", self.get_rev_map().get_categories().clone());
let casted_series = categories.cast(dtype)?;

macro_rules! get_elements {
($ca:expr) => {{
Ok(self
.physical()
.into_iter()
.map(|opt_el| {
opt_el.map(|el: u32| unsafe {
$ca.get_unchecked(el as usize).unwrap()
})
})
.collect())
}};
#[cfg(feature = "bigidx")]
{
let s = self.physical.cast(&DataType::UInt64)?;
Ok(unsafe { casted_series.take_unchecked(s.u64()?) })
}
#[cfg(not(feature = "bigidx"))]
{
// Safety: Invariant of categorical means indices are in bound
Ok(unsafe { casted_series.take_unchecked(&self.physical) })
}
downcast_as_macro_arg_physical!(casted_series, get_elements)
},
_ => self.physical.cast(dtype),
}
Expand Down

0 comments on commit 38d2f70

Please sign in to comment.