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

Wrong results with steaming=True when concat dataframes. #20833

Open
2 tasks done
jhirsch-mhp opened this issue Jan 21, 2025 · 1 comment
Open
2 tasks done

Wrong results with steaming=True when concat dataframes. #20833

jhirsch-mhp opened this issue Jan 21, 2025 · 1 comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@jhirsch-mhp
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

print(f"polars version: {pl.__version__}")

# define simple Dataframe
d = pl.DataFrame({"a": [0,1,2,3]}, schema={"a": pl.Float64})
print(d)

# Make lazy
d = d.lazy()

# split, process and combine again
combined = pl.concat(
    [d.filter(pl.col("a") < 2).with_columns(pl.mean("a")), 
     d.filter(pl.col("a") >= 2)],
    how="vertical"
)

# Show Plans
print("\nPlan:\n", combined.explain())

# See different results for Streaming
print(f"\nStreaming=False: {combined.collect(streaming=False)}")
print(f"Streaming=True: {combined.collect(streaming=True)}")        # <--- This result is wrong

Log output

polars version: 1.20.0
shape: (4, 1)
┌─────┐
│ a   │
│ --- │
│ f64 │
╞═════╡
│ 0.0 │
│ 1.0 │
│ 2.0 │
│ 3.0 │
└─────┘

Plan:
 UNION
  PLAN 0:
     WITH_COLUMNS:
     [col("a").mean()] 
      FILTER [(col("a")) < (2.0)] FROM
        DF ["a"]; PROJECT */1 COLUMNS
  PLAN 1:
    FILTER [(col("a")) >= (2.0)] FROM
      DF ["a"]; PROJECT */1 COLUMNS
END UNION

Streaming=False: shape: (4, 1)
┌─────┐
│ a   │
│ --- │
│ f64 │
╞═════╡
│ 0.5 │
│ 0.5 │
│ 2.0 │
│ 3.0 │
└─────┘
Streaming=True: shape: (2, 1)
┌─────┐
│ a   │
│ --- │
│ f64 │
╞═════╡
│ 2.0 │
│ 3.0 │
└─────┘

Issue description

When using a lazy split -> process -> concat expression, the streaming=True yields a wrong result. It completely drops the part where an expression was done. This is not limited to the mean() function but is also true for any other expression.

PS; I also opened #20694, however I realized that this problem is much more generic then described there and applies to every split -> process -> concat expression. It is therefore much more general and maybe worth a fix. I tagged the other issue as duplicate of this one.

Expected behavior

Same behavior for streaming=True as it is for streaming=False.

Installed versions

--------Version info---------
Polars:              1.20.0
Index type:          UInt32
Platform:            Windows-10-10.0.19045-SP0
Python:              3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)]
LTS CPU:             False

----Optional dependencies----
Azure CLI            <not installed>
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       <not installed>
boto3                1.35.7
cloudpickle          3.0.0
connectorx           <not installed>
deltalake            <not installed>
fastexcel            0.11.6
fsspec               2023.12.2
gevent               <not installed>
google.auth          2.34.0
great_tables         <not installed>
matplotlib           3.9.2
nest_asyncio         1.6.0
numpy                1.24.4
openpyxl             3.1.5
pandas               2.2.2
pyarrow              13.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           2.0.32
torch                2.4.0+cpu
xlsx2csv             0.8.3
xlsxwriter           3.2.0```

</details>
@jhirsch-mhp jhirsch-mhp added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jan 21, 2025
@jhirsch-mhp jhirsch-mhp marked this as a duplicate of #20694 Jan 21, 2025
@orlp
Copy link
Collaborator

orlp commented Jan 21, 2025

My reply is the same as in the previous issue:

This works correctly in the new streaming engine, I'm not sure if it's worth the time to fix this in the old streaming engine if it will be replaced soon.

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