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 all 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
38 changes: 37 additions & 1 deletion crates/polars-plan/src/logical_plan/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,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 opt_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;
new_int_range::<Int32Type>(low, high, 1, "range").ok()
},
DataType::Int64 => {
let low = *low;
let high = *high;
new_int_range::<Int64Type>(low, high, 1, "range").ok()
},
DataType::UInt32 => {
if *low < 0 || *high > u32::MAX as i64 {
return None;
}
let low = *low as u32;
let high = *high as u32;
new_int_range::<UInt32Type>(low, high, 1, "range").ok()
},
_ => return None,
};
match opt_s {
Some(s) => AnyValue::List(s),
None => return None,
}
},
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