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.len() gives wrong results when evaluated on LazyFrame that contains a broadcasted scalar #20046

Closed
2 tasks done
colin-kerkhof opened this issue Nov 28, 2024 · 0 comments · Fixed by #20049
Closed
2 tasks done
Assignees
Labels
A-optimizer Area: plan optimization accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@colin-kerkhof
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

base = pl.DataFrame({"a": [1, 2, 3]})

lazy_len = base.lazy().select(
    pl.col("a"),
    pl.lit(list, allow_object=True).first(),
).select(pl.len()).collect()

df_len = base.select(
    pl.col("a"),
    pl.lit(list, allow_object=True).first(), 
).select(pl.len())

lazy_len.equals(df_len) # False

Log output

No response

Issue description

When using pl.len() on a LazyFrame, after using a scalar series that needs to be broadcasted, it returns 1 as a value instead of the actual number of rows. Collecting without selecting pl.len yields the correct output

Expected behavior

The actual number of rows from the dataframe

Installed versions

Polars:              1.15.0
Index type:          UInt32
Platform:            macOS-15.1.1-arm64-arm-64bit
Python:              3.12.7 (main, Oct  1 2024, 02:05:46) [Clang 16.0.0 (clang-1600.0.26.3)]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
boto3                1.35.60
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            0.22.0
fastexcel            <not installed>
fsspec               2024.10.0
gevent               <not installed>
google.auth          <not installed>
great_tables         <not installed>
matplotlib           3.9.2
nest_asyncio         1.6.0
numpy                2.1.3
openpyxl             <not installed>
pandas               2.2.3
pyarrow              18.0.0
pydantic             2.9.2
pyiceberg            <not installed>
sqlalchemy           2.0.36
torch                2.5.1
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@colin-kerkhof colin-kerkhof added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Nov 28, 2024
@nameexhaustion nameexhaustion added accepted Ready for implementation P-medium Priority: medium A-optimizer Area: plan optimization and removed needs triage Awaiting prioritization by a maintainer labels Nov 28, 2024
@nameexhaustion nameexhaustion self-assigned this Nov 28, 2024
@github-project-automation github-project-automation bot moved this to Ready in Backlog Nov 28, 2024
@github-project-automation github-project-automation bot moved this from Ready to Done in Backlog Nov 28, 2024
@nameexhaustion nameexhaustion removed their assignment Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-optimizer Area: plan optimization accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants