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

Using unique aggregations with StringCache replaces values with null #20539

Closed
2 tasks done
thomas-tran-de opened this issue Jan 3, 2025 · 0 comments · Fixed by #20540
Closed
2 tasks done

Using unique aggregations with StringCache replaces values with null #20539

thomas-tran-de opened this issue Jan 3, 2025 · 0 comments · Fixed by #20540
Assignees
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@thomas-tran-de
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(
    {"number": [1, 1, 2, 2, 3], "letter": ["a", "b", "b", "c", "c"]}
)

with pl.StringCache():
    result = (
        df.cast({"letter": pl.Categorical})
        .group_by("number")
        .agg(
            all=pl.col("letter"),
            unique=pl.col("letter").unique(),
            unique_with_order=pl.col("letter").unique(maintain_order=True),
        )
    )

result.sort("number")

In v 1.17.1 the output is

number all unique unique_with_order
i64 list[cat] list[cat] list[cat]
1 ["a", "b"] ["a", "b"] ["a", "b"]
2 ["b", "c"] ["b", "c"] ["b", "c"]
3 ["c"] ["c"] ["c"]

In v1.80.0 the output is

number all unique unique_with_order
i64 list[cat] list[cat] list[cat]
1 ["a", "b"] ["a", "b"] ["a", "b"]
2 ["b", "c"] ["b", null] ["b", "c"]
3 ["c"] ["c"] ["c"]

Log output

No response

Issue description

Using the unique operator in an aggregation while the StringCache is active, replaces some values with null.

Expected behavior

Behavior as it was in v1.17.1

Installed versions

--------Version info---------
Polars:              1.18.0
Index type:          UInt32
Platform:            Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.39
Python:              3.12.7 (main, Oct 18 2024, 08:38:59) [GCC 13.2.0]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       1.19.0
boto3                <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            0.17.4
fastexcel            <not installed>
fsspec               2024.12.0
gevent               <not installed>
google.auth          2.37.0
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         1.6.0
numpy                2.2.1
openpyxl             <not installed>
pandas               2.2.3
pyarrow              18.1.0
pydantic             2.10.4
pyiceberg            <not installed>
sqlalchemy           2.0.36
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@thomas-tran-de thomas-tran-de added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jan 3, 2025
@ritchie46 ritchie46 self-assigned this Jan 3, 2025
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

Successfully merging a pull request may close this issue.

2 participants