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

pl.struct usage of schema renders keyword argument renaming ineffective #16509

Open
2 tasks done
SandroCasagrande opened this issue May 26, 2024 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@SandroCasagrande
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


pl.DataFrame({"a": 1}).select(
    s = pl.struct(schema={"b": pl.Int64}, b = pl.col("a")),
)

Log output

polars.exceptions.ColumnNotFoundError: b

Issue description

I'm using the named_exprs parameter of pl.struct to easily name fields as explained in the docstring and expect it to act identically to expressions in exprs with an additional alias. This is exactly what happens initially in source, but then the derived alias remains unused since expressions become rebuilt after https://github.com/pola-rs/polars/blame/d856b4987091dce730d8d0c4ffc08b14bf48f8cc/py-polars/polars/functions/as_datatype.py#L585-L586. I guess the check should include not named_exprs, too?

Expected behavior

Identical to

pl.DataFrame({"a": 1}).select(
    s = pl.struct(pl.col("a").alias("b"), schema={"b": pl.Int64})
)

Installed versions

--------Version info---------
Polars:               0.20.30
Index type:           UInt32
Platform:             macOS-14.5-arm64-arm-64bit
Python:               3.11.9 (main, Apr 19 2024, 11:43:47) [Clang 14.0.6 ]
----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               2024.3.1
gevent:               <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             3.1.2
pandas:               2.2.2
pyarrow:              16.0.0
pydantic:             2.7.1
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           2.0.30
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@SandroCasagrande SandroCasagrande added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels May 26, 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

1 participant