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

Regression from 0.17.15: list.eval fails on data frame with single row #9137

Closed
2 tasks done
datenzauberai opened this issue May 31, 2023 · 1 comment · Fixed by #9140
Closed
2 tasks done

Regression from 0.17.15: list.eval fails on data frame with single row #9137

datenzauberai opened this issue May 31, 2023 · 1 comment · Fixed by #9140
Labels
bug Something isn't working python Related to Python Polars

Comments

@datenzauberai
Copy link
Contributor

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

With the new release our code failed when trying to check if a list contains values from another list. This error only occurs when the data frame contains a single row and the list to compare with has more elements than the list element in the data frame.

Reproducible example

import polars as pl

df = pl.DataFrame(
    {
        "row_number": [0, 1],
        "str_list": [["a", "b"], ["c", "d"]],
    }
)

cmp_list = ["a", "b", "c"] # only a or a, b will not error

# this works (filtering to a single row after list evaluation)
(df
    .with_columns(
        pl.col("str_list").list.eval(
            pl.element().is_in(cmp_list)
        ).alias("comparison")
    ).filter(pl.col("row_number")==0)
)

# this errors, but should yield the same result as above (filtering to a single row before list evaluation)
# InvalidOperationError: output length of `map` (3) must be equal to the input length (2); consider using `apply` instead
(df
    .filter(pl.col("row_number")==0)
    .with_columns(
        pl.col("str_list").list.eval(
            pl.element().is_in(cmp_list)
        ).alias("comparison")
    )
)

Expected behavior

The code should work on a data frame with a single row the same way as on a data frame with multiple rows. This used to work in 0.17.5 using the arr namespace.

Installed versions

--------Version info---------
Polars:      0.18.0
Index type:  UInt32
Platform:    macOS-13.3.1-arm64-arm-64bit
Python:      3.11.3 (main, May 13 2023, 07:40:09) [Clang 14.0.3 (clang-1403.0.22.14.1)]

----Optional dependencies----
numpy:       <not installed>
pandas:      <not installed>
pyarrow:     <not installed>
connectorx:  <not installed>
deltalake:   <not installed>
fsspec:      <not installed>
matplotlib:  <not installed>
xlsx2csv:    <not installed>
xlsxwriter:  <not installed>
@datenzauberai
Copy link
Contributor Author

Maybe related:

pl.DataFrame({"id": [], "value": []}).groupby("id").agg(pl.col("value").pow(2).mean()) fails on 0.18.0 and not on 0.17.15

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