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

Another "coalesce=False" join schema issue #16554

Closed
2 tasks done
alexander-beedie opened this issue May 28, 2024 · 2 comments · Fixed by #16559
Closed
2 tasks done

Another "coalesce=False" join schema issue #16554

alexander-beedie opened this issue May 28, 2024 · 2 comments · Fixed by #16559
Assignees
Labels
accepted Ready for implementation bug Something isn't working python Related to Python Polars rust Related to Rust Polars

Comments

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented May 28, 2024

@nameexhaustion: Up for another one? 😉

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import polars as pl

lf1 = pl.LazyFrame({
    "a": [1, 2, 3, 4, 5],
    "b": [1, 2, 3, 4, 5],
})
lf2 = pl.LazyFrame({
    "a": [0, 2, 3, 4, 5],
    "b": [1, 2, 3, 5, 6],
    "c": [7, 5, 3, 5, 7],
})

lf3 = lf1.join(
    other = lf2,
    how = "inner",
    left_on = ["a", "a"],  # << note: joining on `a = b` *and* `a = c`
    right_on = ["b", "c"],
    coalesce = False,
)

lf3.collect()
# shape: (2, 5)
# ┌─────┬─────┬─────────┬─────────┬─────┐
# │ a   ┆ b   ┆ a_right ┆ b_right ┆ c   │
# │ --- ┆ --- ┆ ---     ┆ ---     ┆ --- │
# │ i64 ┆ i64 ┆ i64     ┆ i64     ┆ i64 │
# ╞═════╪═════╪═════════╪═════════╪═════╡
# │ 3   ┆ 3   ┆ 3       ┆ 3       ┆ 3   │
# │ 5   ┆ 5   ┆ 4       ┆ 5       ┆ 5   │
# └─────┴─────┴─────────┴─────────┴─────┘

Now select the columns "a", "b", and "c" from that same LazyFrame:

lf3.select("a", "b", "c").collect()
# DuplicateError: the name: 'a' is duplicate

Issue description

Selecting columns from a post-join LazyFrame can raise an erroneous DuplicateError.

Expected behavior

The above join + select operation should result in the following frame:

# shape: (2, 3)
# ┌─────┬─────┬─────┐
# │ a   ┆ b   ┆ c   │
# │ --- ┆ --- ┆ --- │
# │ i64 ┆ i64 ┆ i64 │
# ╞═════╪═════╪═════╡
# │ 3   ┆ 3   ┆ 3   │
# │ 5   ┆ 5   ┆ 5   │
# └─────┴─────┴─────┘

Installed versions

Compiled current main (as of a few minutes ago) with all standard features.

@alexander-beedie alexander-beedie added bug Something isn't working python Related to Python Polars rust Related to Rust Polars labels May 28, 2024
@ritchie46
Copy link
Member

@nameexhaustion can you take a look?

@nameexhaustion
Copy link
Collaborator

Will take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working python Related to Python Polars rust Related to Rust Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants