-
-
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
ColumnNotFoundError
when using unnest
#19307
Comments
The |
In the mean time you can add a cast to inform Polars of the type. |
There are probably a few issues on the topic that could all be rolled into one:
|
ColumnNotFoundError
when using unnest
ColumnNotFoundError
when using unnest
inside list.eval
ColumnNotFoundError
when using unnest
inside list.eval
ColumnNotFoundError
when using unnest
I think I also encountered a variant of this issue which seemed specifically related to when the I aliased the structed column with a new name. This is a re-producible example of the issue I experienced: import datetime
data = [{'timestamp': datetime.datetime(2024, 9, 30, 16, 5, 19),
'flight': 1,
'conformances': [True,
True,
False]},
{'timestamp': datetime.datetime(2024, 9, 30, 16, 5, 20),
'flight': 2,
'conformances': [False,
False,
False]},
{'timestamp': datetime.datetime(2024, 9, 30, 16, 5, 21),
'flight': 3,
'conformances': [False,
False,
True]}]
ldf = pl.LazyFrame(data)
ldf2 = ldf.with_columns(pl.col('conformances').list.to_struct(fields=['heading', 'level', 'speed']).alias('new_conformances'))
# this works fine
ldf2.unnest('new_conformances').collect().select('heading', 'level', 'speed')
# this raises polars.exceptions.ColumnNotFoundError: heading
ldf2.unnest('new_conformances').drop('flight').collect().select('heading', 'level', 'speed')
|
@DarkAmoeba I can reproduce that on 1.10.0 I think it was fixed by #19439 in 1.11.0 |
Checks
Reproducible example
Log output
No response
Issue description
The code above raises the following error:
I suspect this might be an expected behaviour. I know in case of LazyFrame the schema is validated before executing the query. Since the number of columns cannot be known before execution and since the naming function might be indeterministic, the presence of the resulting columns cannot be verified early.
In case the error is expected, I think it would be useful for users to add a comment to
LazyFrame.unnest
docs.Expected behavior
The query above would complete successfully or an informative warning would be raised.
Installed versions
The text was updated successfully, but these errors were encountered: