Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Jan 7, 2025
1 parent f104170 commit a75a9d6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crates/polars-plan/src/plans/aexpr/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl AExpr {

Function { options, .. } => options.is_elementwise(),

Literal(v) => v.projects_as_scalar(),
Literal(v) => v.is_scalar(),

Alias(_, _) | BinaryExpr { .. } | Column(_) | Ternary { .. } | Cast { .. } => true,

Expand Down
10 changes: 0 additions & 10 deletions crates/polars-plan/src/plans/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,6 @@ impl LiteralValue {
!matches!(self, LiteralValue::Series(_) | LiteralValue::Range { .. })
}

/// Less-strict `is_scalar` check - generally used for internal functionality such as our
/// optimizers.
pub(crate) fn projects_as_scalar(&self) -> bool {
match self {
LiteralValue::Series(s) => s.len() == 1,
LiteralValue::Range { low, high, .. } => high.saturating_sub(*low) == 1,
_ => true,
}
}

pub fn to_any_value(&self) -> Option<AnyValue> {
use LiteralValue::*;
let av = match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn can_pushdown_slice_past_projections(

match ae {
AExpr::Column(_) => has_column = true,
AExpr::Literal(v) => literals_all_scalar &= v.projects_as_scalar(),
AExpr::Literal(v) => literals_all_scalar &= v.is_scalar(),
_ => {},
}

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) fn has_leaf_literal(e: &Expr) -> bool {
#[cfg(feature = "is_in")]
pub(crate) fn all_return_scalar(e: &Expr) -> bool {
match e {
Expr::Literal(lv) => lv.projects_as_scalar(),
Expr::Literal(lv) => lv.is_scalar(),
Expr::Function { options: opt, .. } => opt.flags.contains(FunctionFlags::RETURNS_SCALAR),
Expr::Agg(_) => true,
Expr::Column(_) | Expr::Wildcard => false,
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/unit/test_predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,13 @@ def test_predicate_pushdown_join_19772(

assert_frame_equal(q.collect(no_optimization=True), expect)
assert_frame_equal(q.collect(), expect)


def test_predicate_pushdown_scalar_20489() -> None:
df = pl.DataFrame({"a": [1]})
mask = pl.Series([False])

assert_frame_equal(
df.lazy().with_columns(b=pl.Series([2])).filter(mask).collect(),
pl.DataFrame(schema={"a": pl.Int64, "b": pl.Int64}),
)

0 comments on commit a75a9d6

Please sign in to comment.