Skip to content

Commit

Permalink
fix: to_any_value should supports all LiteralValue type (#15387)
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa authored Mar 31, 2024
1 parent 345ca75 commit ab5c0ee
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
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

0 comments on commit ab5c0ee

Please sign in to comment.