Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: to_any_value should supports all LiteralValue type #15387

Merged
merged 3 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion crates/polars-plan/src/logical_plan/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::hash::{Hash, Hasher};
#[cfg(feature = "temporal")]
use polars_core::export::chrono::{Duration as ChronoDuration, NaiveDate, NaiveDateTime};
use polars_core::prelude::*;
use polars_core::utils::NoNull;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -116,7 +117,43 @@ impl LiteralValue {
DateTime(v, tu, tz) => AnyValue::Datetime(*v, *tu, tz),
#[cfg(feature = "dtype-time")]
Time(v) => AnyValue::Time(*v),
_ => return None,
Series(s) => AnyValue::List(s.0.clone().into_series()),
Range {
low,
high,
data_type,
} => {
let s = match data_type {
DataType::Int32 => {
if *low < i32::MIN as i64 || *high > i32::MAX as i64 {
return None;
}

let low = *low as i32;
let high = *high as i32;
let ca: NoNull<Int32Chunked> = (low..high).collect();
ca.into_inner().into_series()
},
DataType::Int64 => {
let low = *low;
let high = *high;
let ca: NoNull<Int64Chunked> = (low..high).collect();
ca.into_inner().into_series()
},
DataType::UInt32 => {
if *low < 0 || *high > u32::MAX as i64 {
return None;
}
let low = *low as u32;
let high = *high as u32;
let ca: NoNull<UInt32Chunked> = (low..high).collect();
ca.into_inner().into_series()
},
_ => return None,
};
reswqa marked this conversation as resolved.
Show resolved Hide resolved
AnyValue::List(s)
},
Binary(v) => AnyValue::Binary(v),
};
Some(av)
}
Expand Down
2 changes: 2 additions & 0 deletions py-polars/tests/unit/functions/test_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
(8, 2, pl.UInt8, pl.UInt8),
(date(2023, 2, 2), 3, pl.Datetime, pl.Datetime),
(7.5, 5, pl.UInt16, pl.UInt16),
([1, 2, 3], 2, pl.List(pl.Int64), pl.List(pl.Int64)),
(b"ab12", 3, pl.Binary, pl.Binary),
],
)
def test_repeat(
Expand Down
Loading