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(rust, python): fix is_in on empty series #10195

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 2 additions & 11 deletions crates/polars-plan/src/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub use crate::logical_plan::lit;
use crate::prelude::*;
use crate::utils::has_expr;
#[cfg(feature = "is_in")]
use crate::utils::has_root_literal_expr;
use crate::utils::has_leaf_literal;

impl Expr {
/// Modify the Options passed to the `Function` node.
Expand Down Expand Up @@ -1045,16 +1045,7 @@ impl Expr {
#[cfg(feature = "is_in")]
pub fn is_in<E: Into<Expr>>(self, other: E) -> Self {
let other = other.into();
let has_literal = has_root_literal_expr(&other);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produced the wrong length and didn't keep the left sides name. We must go through the engine.

if has_literal
&& match &other {
Expr::Literal(LiteralValue::Series(s)) if s.is_empty() => true,
Expr::Literal(LiteralValue::Null) => true,
_ => false,
}
{
return Expr::Literal(LiteralValue::Boolean(false));
}
let has_literal = has_leaf_literal(&other);

let arguments = &[other];
// we don't have to apply on groups, so this is faster
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-plan/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ where
current_expr.into_iter().any(matches)
}

/// Check if root expression is a literal
/// Check if leaf expression is a literal
#[cfg(feature = "is_in")]
pub(crate) fn has_root_literal_expr(e: &Expr) -> bool {
pub(crate) fn has_leaf_literal(e: &Expr) -> bool {
match e {
Expr::Literal(_) => true,
_ => {
Expand Down
8 changes: 7 additions & 1 deletion py-polars/tests/unit/test_empty.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

import polars as pl
from polars.testing import assert_frame_equal
from polars.testing import assert_frame_equal, assert_series_equal


def test_empty_str_concat_lit() -> None:
Expand Down Expand Up @@ -87,3 +87,9 @@ def test_empty_list_namespace_output_9585() -> None:
assert df.select(
[eval(f"pl.col('A').list.{name}().suffix(f'_{name}')") for name in names]
).dtypes == [dtype] * len(names)


def test_empty_is_in() -> None:
assert_series_equal(
pl.Series("a", [1, 2, 3]).is_in([]), pl.Series("a", [False] * 3)
)
Loading