pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
30.22k stars 1.95k forks source link

Cryptic error message when empty list is passed to all_horizontal #14287

Open antonioalegria opened 9 months ago

antonioalegria commented 9 months ago

Checks

Reproducible example

df = pl.DataFrame(
    {
        "a": [False, False, True, True, False, None],
        "b": [False, True, True, None, None, None],
        "c": ["u", "v", "w", "x", "y", "z"],
    }
)

result = df.filter(pl.all_horizontal([])) # BOOM: ComputeError: cannot return empty fold because the number of output rows is unknown

Log output

Traceback (most recent call last):
  File "test.py", line 66, in <module>
    result = df.filter(pl.all_horizontal([]))
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/polars/functions/aggregation/horizontal.py", line 62, in all_horizontal
    return wrap_expr(plr.all_horizontal(pyexprs))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ComputeError: cannot return empty fold because the number of output rows is unknown

Issue description

The error message is too cryptic. Actually this should either not result in an error or it should give a more explicit error for the arguments of all_horizontal

Expected behavior

Either not raise an error, and yield False, or raise a more explanatory error.

Installed versions

``` Replace this line with the output of pl.show_versions(). Leave the backticks in place. ``` --------Version info--------- Polars: 0.20.7 Index type: UInt32 Platform: macOS-14.2.1-arm64-arm-64bit Python: 3.11.6 (main, Oct 2 2023, 20:46:14) [Clang 14.0.3 (clang-1403.0.22.14.1)] ----Optional dependencies---- adbc_driver_manager: cloudpickle: 2.2.1 connectorx: deltalake: fsspec: 2023.6.0 gevent: hvplot: matplotlib: 3.7.1 numpy: 1.24.3 openpyxl: 3.1.2 pandas: 1.5.3 pyarrow: 12.0.1 pydantic: 1.10.9 pyiceberg: pyxlsb: sqlalchemy: 2.0.18 xlsx2csv: xlsxwriter:
deanm0000 commented 9 months ago

I'll grant you the error is a bit cryptic but if we set that aside for a moment, under the scenario where it doesn't raise an error, what would you expect it to return?

antonioalegria commented 9 months ago

I think raising an error is fine. It could also not raise an error and yield the same result as False. Though that would have to be consistent with other equivalent operations in polars (I don't know enough to say right now).

cmdlineluser commented 9 months ago

Just for reference, the error arose from the discussion here: