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

Nondeterministic execution of value counts + replace #18411

Closed
2 tasks done
Ilykuleshov opened this issue Aug 27, 2024 · 2 comments · Fixed by #18426
Closed
2 tasks done

Nondeterministic execution of value counts + replace #18411

Ilykuleshov opened this issue Aug 27, 2024 · 2 comments · Fixed by #18426
Assignees
Labels
A-optimizer Area: plan optimization accepted Ready for implementation bug Something isn't working python Related to Python Polars

Comments

@Ilykuleshov
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
df = pl.DataFrame({"foo": [0, 0, 0, 1, 1]})
vc = pl.col("foo").value_counts()
classes = vc.struct[0]
counts = vc.struct[1]
df.select(pl.col("foo").replace(classes, counts))

Log output

No response

Issue description

The reproducible example gives different results each run.

Expected behavior

I expected it to output [3, 3, 3, 2, 2]. It sometimes outputs [2, 2, 2, 3, 3].

Installed versions

--------Version info---------
Polars:               1.5.0
Index type:           UInt32
Platform:             Linux-5.15.0-94-generic-x86_64-with-glibc2.35
Python:               3.10.12 (main, Mar 22 2024, 16:50:05) [GCC 11.4.0]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          3.0.0
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               2024.2.0
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           3.8.3
nest_asyncio:         1.6.0
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.1
pyarrow:              15.0.0
pydantic:             <not installed>
pyiceberg:            <not installed>
sqlalchemy:           <not installed>
torch:                2.2.1+cu121
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>```

</details>
@Ilykuleshov Ilykuleshov added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Aug 27, 2024
@cmdlineluser
Copy link
Contributor

You can make it deterministic with .value_counts(sort=True)

It's a sneaky one - as it doesn't happen with .lazy() because CSE caches the result and value_counts() is executed just once.

@deanm0000 deanm0000 removed the needs triage Awaiting prioritization by a maintainer label Aug 27, 2024
@ritchie46
Copy link
Member

Right.. Also a tough one to fix. I think we should enable cse on eager from now on.

@nameexhaustion nameexhaustion added the A-optimizer Area: plan optimization label Aug 28, 2024
@c-peters c-peters added the accepted Ready for implementation label Sep 3, 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 python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants