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

bug: Unable to get the length of a polars lazyframe with version 1.20.0 #20831

Open
2 tasks done
Matt711 opened this issue Jan 21, 2025 · 0 comments
Open
2 tasks done
Assignees
Labels
A-optimizer Area: plan optimization accepted Ready for implementation bug Something isn't working python Related to Python Polars regression Issue introduced by a new release

Comments

@Matt711
Copy link

Matt711 commented Jan 21, 2025

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

With polars==1.20.0

In [1]: import polars as pl

In [2]: left=pl.LazyFrame(
   ...:         {
   ...:             "a": [1, 2, 3, 1, None],
   ...:             "b": [1, 2, 3, 4, 5],
   ...:             "c": [2, 3, 4, 5, 6],
   ...:         }
   ...:     )

In [3]: right=pl.LazyFrame(
   ...:         {
   ...:             "a": [1, 4, 3, 7, None, None, 1],
   ...:             "c": [2, 3, 4, 5, 6, 7, 8],
   ...:             "d": [6, None, 7, 8, -1, 2, 4],
   ...:         }
   ...:     )

In [4]: q = left.join_where(right, *[pl.col("b") * 2 <= pl.col("a_right"), pl.col("a") < pl.col("c_right")])

In [5]: q.select(pl.len()).collect()
DuplicateError: the name 'a' is duplicate

Log output

join parallel: true
IEJOIN join dataframes finished
---------------------------------------------------------------------------
DuplicateError                            Traceback (most recent call last)
Cell In[5], line 1
----> 1 q.select(pl.len()).collect()

File ~/.conda/envs/rapids/lib/python3.12/site-packages/polars/lazyframe/frame.py:2056, in LazyFrame.collect(self, type_coercion, _type_check, predicate_pushdown, projection_pushdown, simplify_expression, slice_pushdown, comm_subplan_elim, comm_subexpr_elim, cluster_with_columns, collapse_joins, no_optimization, streaming, engine, background, _check_order, _eager, **_kwargs)
   2054 # Only for testing purposes
   2055 callback = _kwargs.get("post_opt_callback", callback)
-> 2056 return wrap_df(ldf.collect(callback))

DuplicateError: the name 'a' is duplicate

It's possible that multiple expressions are returning the same default column name. If this is the case, try renaming the columns with `.alias("new_name")` to avoid duplicate column names.

Issue description

The difference might be due to this PR: #20223

Expected behavior

With polars==1.17.1

In [1]: import polars as pl

In [2]: left=pl.LazyFrame(
   ...:         {
   ...:             "a": [1, 2, 3, 1, None],
   ...:             "b": [1, 2, 3, 4, 5],
   ...:             "c": [2, 3, 4, 5, 6],
   ...:         }
   ...:     )

In [3]: right=pl.LazyFrame(
   ...:         {
   ...:             "a": [1, 4, 3, 7, None, None, 1],
   ...:             "c": [2, 3, 4, 5, 6, 7, 8],
   ...:             "d": [6, None, 7, 8, -1, 2, 4],
   ...:         }
   ...:     )

In [4]: q = left.join_where(right, *[pl.col("b") * 2 <= pl.col("a_right"), pl.col("a") < pl.col("c_right")])

In [5]: q.select(pl.len()).collect()
join parallel: true
IEJOIN join dataframes finished
Out[5]: 
shape: (1, 1)
┌─────┐
│ len │
│ --- │
│ u32 │
╞═════╡
│ 6   │
└─────┘

Installed versions

--------Version info---------
Polars:              1.20.0
Index type:          UInt32
Platform:            Linux-5.4.0-182-generic-x86_64-with-glibc2.35
Python:              3.12.8 | packaged by conda-forge | (main, Dec  5 2024, 14:24:40) [GCC 13.3.0]
LTS CPU:             False

----Optional dependencies----
Azure CLI            <not installed>
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       <not installed>
boto3                1.36.1
cloudpickle          3.1.1
connectorx           <not installed>
deltalake            <not installed>
fastexcel            0.12.1
fsspec               2024.12.0
gevent               <not installed>
google.auth          <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         1.6.0
numpy                2.0.2
openpyxl             3.1.5
pandas               2.2.3
pyarrow              18.1.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           2.0.37
torch                2.5.1.post303
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@Matt711 Matt711 added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jan 21, 2025
@nameexhaustion nameexhaustion added regression Issue introduced by a new release accepted Ready for implementation A-optimizer Area: plan optimization and removed needs triage Awaiting prioritization by a maintainer labels Jan 22, 2025
@nameexhaustion nameexhaustion self-assigned this Jan 22, 2025
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 python Related to Python Polars regression Issue introduced by a new release
Projects
None yet
Development

No branches or pull requests

2 participants