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

Expr.shrink_dtype() breaks broadcasting #18755

Closed
2 tasks done
guyrosin opened this issue Sep 15, 2024 · 0 comments · Fixed by #18958
Closed
2 tasks done

Expr.shrink_dtype() breaks broadcasting #18755

guyrosin opened this issue Sep 15, 2024 · 0 comments · Fixed by #18958
Assignees
Labels
accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars regression Issue introduced by a new release

Comments

@guyrosin
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,2], "b":[3,4]}).with_columns(pl.lit(5))  # OK
pl.DataFrame({"a":[1,2], "b":[3,4]}).with_columns(pl.lit(5).shrink_dtype().first())  # OK

pl.DataFrame({"a":[1,2], "b":[3,4]}).with_columns(pl.lit(5).shrink_dtype())  # InvalidOperationError

Log output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/playground/.venv/lib/python3.11/site-packages/polars/dataframe/frame.py", line 9141, in with_columns
    return self.lazy().with_columns(*exprs, **named_exprs).collect(_eager=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/playground/.venv/lib/python3.11/site-packages/polars/lazyframe/frame.py", line 2032, in collect
    return wrap_df(ldf.collect(callback))
                   ^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.InvalidOperationError: Series literal, length 1 doesn't match the DataFrame height of 2

If you want this Series to be broadcasted, ensure it is a scalar (for instance by adding '.first()').

Issue description

Broadcasting a literal doesn't work after calling shrink_dtype().
The error message is helpful and explains the problem, but I find it nonintuitive - shrink_dtype() should just shrink the type, nothing more :)

Expected behavior

I expected the shrunk literal to be broadcasted.

Installed versions

pl.show_versions()
--------Version info---------
Polars:              1.7.1
Index type:          UInt32
Platform:            Linux-6.5.0-1024-aws-x86_64-with-glibc2.35
Python:              3.11.9 (main, Jul 13 2024, 23:44:43) [Clang 17.0.6 ]

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               5.4.1
cloudpickle          3.0.0
connectorx           <not installed>
deltalake            <not installed>
fastexcel            0.11.6
fsspec               2024.9.0
gevent               <not installed>
great_tables         <not installed>
matplotlib           3.9.2
nest_asyncio         1.6.0


numpy                1.26.4
openpyxl             <not installed>
pandas               2.2.2
pyarrow              17.0.0
pydantic             2.9.1
pyiceberg            <not installed>
sqlalchemy           2.0.34
torch                2.2.2+cu121
xlsx2csv             0.8.3
xlsxwriter           <not installed>
@guyrosin guyrosin added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Sep 15, 2024
@nameexhaustion nameexhaustion added regression Issue introduced by a new release accepted Ready for implementation P-medium Priority: medium and removed needs triage Awaiting prioritization by a maintainer labels Sep 26, 2024
@github-project-automation github-project-automation bot moved this to Ready in Backlog Sep 26, 2024
@nameexhaustion nameexhaustion self-assigned this Sep 27, 2024
@github-project-automation github-project-automation bot moved this from Ready to Done in Backlog Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars regression Issue introduced by a new release
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants