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

New streaming engine incorrectly sets sorted flag for lexical categorical in partition_by #20440

Open
2 tasks done
coastalwhite opened this issue Dec 24, 2024 · 2 comments
Open
2 tasks done
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@coastalwhite
Copy link
Collaborator

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 os
import polars as pl

os.environ['POLARS_AUTO_NEW_STREAMING'] = '1'

df = pl.DataFrame({"x": [0, 1, 1], "y": ["B", "B", "A"]}).with_columns(
    pl.col("y").cast(pl.Categorical(ordering="lexical"))
)

second_part = df.partition_by("x")[1]
print(second_part._to_metadata('y', 'sorted_asc'))
print(second_part)

Log output

shape: (1, 2)
┌─────────────┬────────────┐
│ column_name ┆ sorted_asc │
│ ---         ┆ ---        │
│ str         ┆ bool       │
╞═════════════╪════════════╡
│ y           ┆ true       │
└─────────────┴────────────┘
shape: (2, 2)
┌─────┬─────┐
│ x   ┆ y   │
│ --- ┆ --- │
│ i64 ┆ cat │
╞═════╪═════╡
│ 1   ┆ B   │
│ 1   ┆ A   │
└─────┴─────┘

Issue description

Sorted flag is incorrectly set.

Expected behavior

Sorted flag should not be set.

Installed versions

Replace this line with the output of pl.show_versions(). Leave the backticks in place.
@coastalwhite coastalwhite added bug Something isn't working python Related to Python Polars needs triage Awaiting prioritization by a maintainer labels Dec 24, 2024
@coastalwhite
Copy link
Collaborator Author

Another possibly related issue.

import os
import polars as pl

os.environ['POLARS_AUTO_NEW_STREAMING'] = '1'

df = pl.DataFrame(
    {"cats": ["z", "z", "k", "a", "b"], "vals": [3, 1, 2, 2, 3]}
).with_columns(
    pl.col("cats").cast(pl.Categorical("lexical")),
)

out = df.sort(["cats"])
print(out)
shape: (5, 2)
┌──────┬──────┐
│ cats ┆ vals │
│ ---  ┆ ---  │
│ cat  ┆ i64  │
╞══════╪══════╡
│ z    ┆ 3    │
│ z    ┆ 1    │
│ k    ┆ 2    │
│ a    ┆ 2    │
│ b    ┆ 3    │
└──────┴──────┘

@siddharth-vi
Copy link
Contributor

Related issue - #19900

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