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

Unexpected interaction between pl.when and pl.struct #15703

Closed
2 tasks done
LucasBou opened this issue Apr 16, 2024 · 1 comment
Closed
2 tasks done

Unexpected interaction between pl.when and pl.struct #15703

LucasBou opened this issue Apr 16, 2024 · 1 comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@LucasBou
Copy link

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

import polars as pl

colint = pl.col("int")
colstr = pl.col("str")

a_struct = pl.struct(colint, colstr)
is_first_line = pl.col("id") == 1

resulting_expr = pl.when(is_first_line).then(a_struct)

data = pl.DataFrame({"id": [1, 2], "int": [5, 5], "str": ["str1", "str2"]})

result = data.select(resulting_expr)
print(data)
print(result)

Log output

No response

Issue description

When using a pl.Struct as the output of a when-then-otherwise expression and no otherwise clause is declared, we get a Struct with null fields.

Expected behavior

I would expect a null to be output instead of a struct with null fields, which would be consistent with the pl.when documentation :

If none of the conditions are True, an optional .otherwise() can be appended at the end. If not appended, and none of the conditions are True, None will be returned.

Installed versions

--------Version info---------
Polars:               0.20.21
Index type:           UInt32
Platform:             Windows-10-10.0.19045-SP0
Python:               3.12.2 (tags/v3.12.2:6abddd9, Feb  6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.1
pyarrow:              <not installed>
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@LucasBou LucasBou added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Apr 16, 2024
@orlp
Copy link
Collaborator

orlp commented Apr 16, 2024

This is a duplicate of #3462. Currently structs do not have outer nullability, and it would be a lot of work to add it.

@orlp orlp closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

2 participants