Skip to content

Commit

Permalink
fix: invalid schema outer join after projection pd (pola-rs#13315)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Dec 29, 2023
1 parent e27039f commit 7023bf6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 0 additions & 2 deletions crates/polars-core/src/series/implementations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ mod string;
#[cfg(feature = "dtype-struct")]
mod struct_;

#[cfg(feature = "object")]
use std::any::Any;
use std::borrow::Cow;
use std::ops::{BitAnd, BitOr, BitXor, Deref};
Expand Down Expand Up @@ -427,7 +426,6 @@ macro_rules! impl_dyn_series {
self.0.checked_div(rhs)
}

#[cfg(feature = "object")]
fn as_any(&self) -> &dyn Any {
&self.0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(super) fn datetime_range(
(DataType::Datetime(_, _), None) => start.dtype().clone(),
// overwrite time unit, keep timezone
(DataType::Datetime(_, tz), Some(tu)) => DataType::Datetime(tu, tz.clone()),
_ => unreachable!(),
(dt, _) => polars_bail!(InvalidOperation: "expected a temporal datatype, got {}", dt),
};

// overwrite time zone, if specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,16 @@ pub(super) fn process_join(
.unwrap();
already_added_local_to_local_projected.insert(local_name);
}
// In outer joins both columns remain. So `add_local=true` also for the right table
let add_local = matches!(options.args.how, JoinType::Outer { coalesce: false });
for e in &right_on {
add_keys_to_accumulated_state(
*e,
&mut pushdown_right,
&mut local_projection,
&mut names_right,
expr_arena,
false,
add_local,
);
}

Expand Down
14 changes: 14 additions & 0 deletions py-polars/tests/unit/test_projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,17 @@ def test_projection_count_11841() -> None:
pl.LazyFrame({"x": 1}).select(records=pl.count()).select(
pl.lit(1).alias("x"), pl.all()
).collect()


def test_schema_outer_join_projection_pd_13287() -> None:
lf = pl.LazyFrame({"a": [1, 1], "b": [2, 3]})
lf2 = pl.LazyFrame({"a": [1, 1], "c": [2, 3]})

assert lf.join(
lf2,
how="outer",
left_on="a",
right_on="c",
).with_columns(
pl.col("a").fill_null(pl.col("c")),
).select("a").collect().to_dict(as_series=False) == {"a": [2, 3, 1, 1]}

0 comments on commit 7023bf6

Please sign in to comment.