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

sort_by("col", nulls_last=True).over("other") does not put nulls at the end #17243

Closed
2 tasks done
Alex23rodriguez opened this issue Jun 27, 2024 · 2 comments · Fixed by #17249
Closed
2 tasks done

sort_by("col", nulls_last=True).over("other") does not put nulls at the end #17243

Alex23rodriguez opened this issue Jun 27, 2024 · 2 comments · Fixed by #17249
Labels
A-ops-sort Area: sorting operations bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@Alex23rodriguez
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

For example:

df = pl.DataFrame(
    {
        "a": [1, 10, 9, 3, 2, 4, 7, 5, 6, 8, None, None],
        "b": [1, 2, 3, 1, 4, 2, 3, 3, 2, 1, 1, 2],
    }
)

print(df.select(pl.all().sort_by("a", nulls_last=True).over("b")))

gives

shape: (12, 2)
┌──────┬─────┐
│ a    ┆ b   │
│ ---  ┆ --- │
│ i64  ┆ i64 │
╞══════╪═════╡
│ null ┆ 1   │
│ null ┆ 2   │
│ 5    ┆ 3   │
│ 1    ┆ 1   │
│ 2    ┆ 4   │
│ 4    ┆ 2   │
│ 7    ┆ 3   │
│ 9    ┆ 3   │
│ 6    ┆ 2   │
│ 3    ┆ 1   │
│ 8    ┆ 1   │
│ 10   ┆ 2   │
└──────┴─────┘

Log output

No response

Issue description

nulls_last parameter does not put null values at the end

Expected behavior

the desired output should look something like this:

shape: (12, 2)
┌──────┬─────┐
│ a    ┆ b   │
│ ---  ┆ --- │
│ i64  ┆ i64 │
╞══════╪═════╡
│ 4    ┆ 2   │
│ 1    ┆ 1   │
│ 3    ┆ 1   │
│ 6    ┆ 2   │
│ 5    ┆ 3   │
│ 7    ┆ 3   │
│ 10   ┆ 2   │
│ 2    ┆ 4   │
│ 8    ┆ 1   │
│ 9    ┆ 3   │
│ null ┆ 2   │
│ null ┆ 1   │
└──────┴─────┘

Installed versions

--------Version info---------
Polars:               0.20.31
Index type:           UInt32
Platform:             macOS-14.5-arm64-arm-64bit
Python:               3.11.6 (main, Jun  4 2024, 10:11:53) [Clang 15.0.0 (clang-1500.1.0.2.5)]
@Alex23rodriguez Alex23rodriguez added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jun 27, 2024
@mcrumiller
Copy link
Contributor

To clarify, this only occurs when .over(...) is used.

@Alex23rodriguez Alex23rodriguez changed the title sort_by("col", nulls_last=True) does not put nulls at the end sort_by("col", nulls_last=True).over("other") does not put nulls at the end Jun 27, 2024
@Alex23rodriguez
Copy link
Author

Thanks for pointing this out. I updated the title to reflect this

@stinodego stinodego added P-medium Priority: medium A-ops-sort Area: sorting operations and removed needs triage Awaiting prioritization by a maintainer labels Jun 28, 2024
@github-project-automation github-project-automation bot moved this to Ready in Backlog Jun 28, 2024
@github-project-automation github-project-automation bot moved this from Ready to Done in Backlog Jun 28, 2024
@Alex23rodriguez Alex23rodriguez changed the title sort_by("col", nulls_last=True).over("other") does not put nulls at the end sort_by("col", nulls_last=True).over("other")) does not put nulls at the end Jun 28, 2024
@Alex23rodriguez Alex23rodriguez changed the title sort_by("col", nulls_last=True).over("other")) does not put nulls at the end sort_by("col", nulls_last=True).over("other") does not put nulls at the end Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ops-sort Area: sorting operations bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants