Skip to content

Commit

Permalink
allow join on same cat source (#3363)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed May 11, 2022
1 parent eaabf69 commit 2d94240
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ impl RevMapping {
pub fn same_src(&self, other: &Self) -> bool {
match (self, other) {
(RevMapping::Global(_, _, l), RevMapping::Global(_, _, r)) => *l == *r,
(RevMapping::Local(l), RevMapping::Local(r)) => {
std::ptr::eq(l as *const Utf8Array<_>, r as *const Utf8Array<_>)
}
_ => false,
}
}
Expand Down
13 changes: 13 additions & 0 deletions py-polars/tests/test_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ def test_semi_anti_join() -> None:
"b": ["c"],
"payload": [30],
}


def test_join_same_cat_src() -> None:
df = pl.DataFrame(
data={"column": ["a", "a", "b"], "more": [1, 2, 3]},
columns=[("column", pl.Categorical), ("more", pl.Int32)],
)
df_agg = df.groupby("column").agg(pl.col("more").mean())
assert df.join(df_agg, on="column").to_dict(False) == {
"column": ["a", "a", "b"],
"more": [1, 2, 3],
"more_right": [1.5, 1.5, 3.0],
}

0 comments on commit 2d94240

Please sign in to comment.