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

Coalesce gives different output with pl.col #5502

Closed
2 tasks done
braaannigan opened this issue Nov 14, 2022 · 0 comments · Fixed by #5521
Closed
2 tasks done

Coalesce gives different output with pl.col #5502

braaannigan opened this issue Nov 14, 2022 · 0 comments · Fixed by #5521
Labels
bug Something isn't working python Related to Python Polars

Comments

@braaannigan
Copy link
Collaborator

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

I get incorrect output from pl.coalesce if I pass the columns inside pl.col instead of just as a list of strings - it's only using the first column in the expression.

Reproducible example

import polars as pl
df = pl.DataFrame(
    {
        "a":[10,None,22,None],
        "b":[8,12,19,1],        
        "c":[5,1,19,None],
    }
)
(
    df
    .with_column(
        pl.coalesce(pl.col(["c","b","a"])).alias("d")
    )
)
shape: (4, 4)
┌──────┬─────┬──────┬──────┐
│ abcd    │
│ ------------  │
│ i64i64i64i64  │
╞══════╪═════╪══════╪══════╡
│ 108510   │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ null121null │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 22191922   │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ null1nullnull │
└──────┴─────┴──────┴──────┘

Expected behavior

Expect to get the same behaviour as this

(
    df
    .with_column(
        pl.coalesce(["c","b","a"]).alias("d")
    )
)
shape: (4, 4)
┌──────┬─────┬──────┬─────┐
│ a    ┆ b   ┆ c    ┆ d   │
│ ---  ┆ --- ┆ ---  ┆ --- │
│ i64  ┆ i64 ┆ i64  ┆ i64 │
╞══════╪═════╪══════╪═════╡
│ 10   ┆ 8   ┆ 5    ┆ 5   │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┤
│ null ┆ 12  ┆ 1    ┆ 1   │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┤
│ 22   ┆ 19  ┆ 19   ┆ 19  │
├╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌┤
│ null ┆ 1   ┆ null ┆ 1   │
└──────┴─────┴──────┴─────┘

Installed versions

---Version info---
Polars: 0.14.27
Index type: UInt32
Platform: Linux-5.10.104-linuxkit-x86_64-with-glibc2.28
Python: 3.10.1 (main, Dec 21 2021, 09:50:13) [GCC 8.3.0]
---Optional dependencies---
pyarrow: 10.0.0
pandas: 1.5.1
numpy: 1.23.4
fsspec: <not installed>
connectorx: 0.3.1
xlsx2csv: 0.8
matplotlib: <not installed>
@braaannigan braaannigan added bug Something isn't working python Related to Python Polars labels Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant