Skip to content

Commit

Permalink
feat(python): allow more pyarrow literals (#5842)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 18, 2022
1 parent eb3c6c1 commit 36c72c8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions polars/polars-lazy/polars-plan/src/logical_plan/pyarrow.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use polars_core::datatypes::{AnyValue, DataType};

use crate::prelude::*;

// convert to a pyarrow expression that can be evaluated with pythons eval
Expand All @@ -23,6 +25,24 @@ pub(super) fn predicate_to_pa(predicate: Node, expr_arena: &Arena<AExpr>) -> Opt
} else if dtype.is_integer() {
let val = av.extract::<i64>()?;
Some(format!("{}", val))
} else if matches!(dtype, DataType::Utf8) {
let val = match &av {
AnyValue::Utf8(s) => s,
AnyValue::Utf8Owned(s) => s.as_str(),
_ => unreachable!(),
};
Some(val.to_string())
} else if matches!(dtype, DataType::Boolean) {
if let AnyValue::Boolean(val) = av {
// python bools are capitalized
if val {
Some("True".to_string())
} else {
Some("False".to_string())
}
} else {
None
}
} else {
None
}
Expand Down

0 comments on commit 36c72c8

Please sign in to comment.