-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
first()
returns wrong result on empty Dataframe with struct column
#15727
Comments
Can reproduce. Also happens with >>> df.select(pl.col('col1').last())
shape: (1, 1)
┌──────────────────┐
│ col1 │
│ --- │
│ struct[3] │
╞══════════════════╡
│ {null,null,null} │
└──────────────────┘ Doesn't happen with >>> df.select(pl.col('col1').slice(0, 1))
shape: (0, 1)
┌───────────┐
│ col1 │
│ --- │
│ struct[3] │
╞═══════════╡
└───────────┘ |
I'll fix this tomorrow. |
Wait a second, this is actually currently 'correct', until we add outer nullability for structs. >>> pl.DataFrame({"x": []}, schema={"x": pl.Int64}).select(pl.col.x.last())
shape: (1, 1)
┌──────┐
│ x │
│ --- │
│ i64 │
╞══════╡
│ null │
└──────┘ For structs this currently means returning an all-null row, since structs currently lack outer nullability. I will close this issue as a duplicate of #3462. |
Ah - I thought the issue was that it returned 1 row for a frame of height 0. But that happens regardless of the dtype. df = pl.DataFrame({"foo": []}).cast(pl.String)
# shape: (0, 1)
# ┌─────┐
# │ foo │
# │ --- │
# │ str │
# ╞═════╡
# └─────┘
df.select(pl.first("foo"))
# shape: (1, 1)
# ┌──────┐
# │ foo │
# │ --- │
# │ str │
# ╞══════╡
# │ null │
# └──────┘ |
Yes, Iunderstood from @orlp answers. |
Yes, the term that seems to be used for this is: introduces a "phantom row". I'm not sure if this is expected or not - or if it has been previously discussed. As the title/example was about structs - it seemed like you may have been talking about the other problem. (struct validity) Perhaps you could create an issue without mentioning structs to discuss the |
@cmdlineluser you are right. |
Checks
Reproducible example
Log output
No response
Issue description
On above example we get:
Instead of getting empy dataframe.
Expected behavior
Expected output:
Installed versions
The text was updated successfully, but these errors were encountered: