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

Invalid state DataFrame creatable (columns with different lengths) #12367

Closed
2 tasks done
Julian-J-S opened this issue Nov 10, 2023 · 1 comment · Fixed by #12401
Closed
2 tasks done

Invalid state DataFrame creatable (columns with different lengths) #12367

Julian-J-S opened this issue Nov 10, 2023 · 1 comment · Fixed by #12401
Labels
bug Something isn't working python Related to Python Polars

Comments

@Julian-J-S
Copy link
Contributor

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

df = pl.DataFrame(
    {
        "a": [1, 2],
        "b": [None, None],
    }
)

# this DataFame has unequal column lengths (1 and 0) but CAN be created
df2 = df.select(
    pl.all().drop_nulls().first().name.suffix("_first"),
)

# printing panics
print(df2) # PanicException: The column lengths in the DataFrame are not equal.

# but can still work with it
df2.with_columns(
    pl.all().len()
)
shape: (1, 2)
┌─────────┬─────────┐
│ a_firstb_first │
│ ------     │
│ u32u32     │
╞═════════╪═════════╡
│ 10       │
└─────────┴─────────┘

Log output

No response

Issue description

It is possible to create an (invalid?) DataFrame with different column lengths.
Should this be possible?

Expected behavior

It should not be possible to create/calculate a DataFrame with different column lengths.

I think the cause for this is probably (almost) always that some functions return a zero-sized DataFrame which is somehow accepted and not broadcasted correctly? (I came across this when looking into #12363 where first/last return 0-size dfs)

Installed versions

0.19.12
@Julian-J-S Julian-J-S added bug Something isn't working python Related to Python Polars labels Nov 10, 2023
@ritchie46
Copy link
Member

You deserve a sticker for finding this! :D

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.

2 participants