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

Confusing error message in when when using, for example, min instead of min_horizontal #11139

Closed
2 tasks done
daniel-vainsencher opened this issue Sep 15, 2023 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@daniel-vainsencher
Copy link

daniel-vainsencher commented Sep 15, 2023

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

On 0.19.2:

import polars as pl

df = pl.DataFrame(
    {
        "A": [None, 1.],
        "B": [2, 3.],
    }
)

df.with_columns([
     pl.when(pl.col("A").is_null())
     .then(pl.col("B"))
#     .otherwise(pl.min_horizontal(["A", "B"]))
     .otherwise(pl.min(["A", "B"]))
     .alias("C"),
])
# raises "ComputeError: The name: 'C' passed to `LazyFrame.with_columns` is duplicate"

Log output

$ POLARS_VERBOSE=1 python bug_demo.py
Traceback (most recent call last):
  File "/home/danielv/InsurePayWork/IPDS2/nbs/API/bug_demo.py", line 9, in <module>
    df.with_columns([
  File "/home/danielv/InsurePayWork/venv1/lib/python3.10/site-packages/polars/dataframe/frame.py", line 7859, in with_columns
    self.lazy()
  File "/home/danielv/InsurePayWork/venv1/lib/python3.10/site-packages/polars/utils/deprecation.py", line 95, in wrapper
    return function(*args, **kwargs)
  File "/home/danielv/InsurePayWork/venv1/lib/python3.10/site-packages/polars/lazyframe/frame.py", line 1695, in collect
    return wrap_df(ldf.collect())
exceptions.ComputeError: The name: 'C' passed to `LazyFrame.with_columns` is duplicate

Error originated just after this operation:
DF ["A", "B"]; PROJECT */2 COLUMNS; SELECTION: "None"

Issue description

On 0.18.15 this problem did not arise, because min supported horizontal operation, but it can also arise out of other types of user error.

Expected behavior

The ideal error message would let me know that the number of columns in one of the branches of the conditional is 2 and should be 1. Unless that is actually somehow allowed, and then it should say the number of columns is inconsistent across branches.

The fact that downstream, that seems to cause there to be 2 "C" columns is an implementation detail, and didn't help me understand my (now) misuse of min .

Installed versions

--------Version info---------
Polars:              0.19.2
Index type:          UInt32
Platform:            Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python:              3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0]

----Optional dependencies----
adbc_driver_sqlite:  <not installed>
cloudpickle:         <not installed>
connectorx:          0.3.2_alpha.2
deltalake:           <not installed>
fsspec:              <not installed>
matplotlib:          3.7.1
numpy:               1.24.2
pandas:              2.0.0
pyarrow:             11.0.0
pydantic:            <not installed>
sqlalchemy:          <not installed>
xlsx2csv:            <not installed>
xlsxwriter:          <not installed>
None
@daniel-vainsencher daniel-vainsencher added bug Something isn't working python Related to Python Polars labels Sep 15, 2023
@daniel-vainsencher daniel-vainsencher changed the title Confusing error message when using min instead of min_horizontal Confusing error message in when when using, for example, min instead of min_horizontal Sep 15, 2023
@cmdlineluser
Copy link
Contributor

Related: #11060

@daniel-vainsencher
Copy link
Author

Having thought about it a bit more, a different expected behavior would be that simply calling alias on an expression of multiple columns should cause an error about that.

@stinodego stinodego added the needs triage Awaiting prioritization by a maintainer label Jan 13, 2024
@stinodego
Copy link
Member

Closing in favor of #11060

@stinodego stinodego closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

3 participants