Skip to content

Commit

Permalink
fix(rust): tag IntoSeries trait as unsafe (#5258)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 19, 2022
1 parent 598401b commit 5a1c744
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
13 changes: 10 additions & 3 deletions polars/polars-core/src/series/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,14 @@ impl TryFrom<(&str, ArrayRef)> for Series {
}
}

pub trait IntoSeries {
/// Used to convert a [`ChunkedArray`], `&dyn SeriesTrait` and [`Series`]
/// into a [`Series`].
/// # Safety
///
/// This trait is marked `unsafe` as the `is_series` return is used
/// to transmute to `Series`. This must always return `false` except
/// for `Series` structs.
pub unsafe trait IntoSeries {
fn is_series() -> bool {
false
}
Expand Down Expand Up @@ -527,13 +534,13 @@ impl From<TimeChunked> for Series {
}
}

impl IntoSeries for Arc<dyn SeriesTrait> {
unsafe impl IntoSeries for Arc<dyn SeriesTrait> {
fn into_series(self) -> Series {
Series(self)
}
}

impl IntoSeries for Series {
unsafe impl IntoSeries for Series {
fn is_series() -> bool {
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::frame::hash_join::ZipOuterJoinColumn;
use crate::prelude::*;
use crate::series::implementations::SeriesWrap;

impl IntoSeries for CategoricalChunked {
unsafe impl IntoSeries for CategoricalChunked {
fn into_series(self) -> Series {
Series(Arc::new(SeriesWrap(self)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::prelude::*;

macro_rules! impl_dyn_series {
($ca: ident, $into_logical: ident) => {
impl IntoSeries for $ca {
unsafe impl IntoSeries for $ca {
fn into_series(self) -> Series {
Series(Arc::new(SeriesWrap(self)))
}
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/implementations/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::frame::groupby::*;
use crate::frame::hash_join::*;
use crate::prelude::*;

impl IntoSeries for DatetimeChunked {
unsafe impl IntoSeries for DatetimeChunked {
fn into_series(self) -> Series {
Series(Arc::new(SeriesWrap(self)))
}
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/implementations/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::frame::groupby::*;
use crate::frame::hash_join::*;
use crate::prelude::*;

impl IntoSeries for DurationChunked {
unsafe impl IntoSeries for DurationChunked {
fn into_series(self) -> Series {
Series(Arc::new(SeriesWrap(self)))
}
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/implementations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<T: PolarsDataType> Deref for SeriesWrap<ChunkedArray<T>> {
}
}

impl<T: PolarsDataType + 'static> IntoSeries for ChunkedArray<T>
unsafe impl<T: PolarsDataType + 'static> IntoSeries for ChunkedArray<T>
where
SeriesWrap<ChunkedArray<T>>: SeriesTrait,
{
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/implementations/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
use crate::prelude::*;
use crate::series::private::{PrivateSeries, PrivateSeriesNumeric};

impl IntoSeries for StructChunked {
unsafe impl IntoSeries for StructChunked {
fn into_series(self) -> Series {
Series(Arc::new(SeriesWrap(self)))
}
Expand Down

0 comments on commit 5a1c744

Please sign in to comment.