pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust

Home Page:https://docs.pola.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic when sorting DataFrame by Null column

stinodego opened this issue · comments

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({"a": [None], "b": [1]})
result = df.sort("a")
print(result)

Log output

thread '<unnamed>' panicked at crates/polars-core/src/series/series_trait.rs:363:9:
`arg_sort` operation not supported for dtype `null`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/home/stijn/code/polars/py-polars/repro.py", line 9, in <module>
    result = df.sort("a")
             ^^^^^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/dataframe/frame.py", line 4727, in sort
    .collect(_eager=True)
     ^^^^^^^^^^^^^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/lazyframe/frame.py", line 1896, in collect
    return wrap_df(ldf.collect(callback))
                   ^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: `arg_sort` operation not supported for dtype `null`

Issue description

Sorting panics when sorting by a Null column.

There is no issue if the null column is the only column being sorted.

The same happens when sorting a Struct Series, though this gives a proper error (should still just work though):

s = pl.Series([{"a": None, "b": 1}])
result = s.sort()
Traceback (most recent call last):
  File "/home/stijn/code/polars/py-polars/repro.py", line 8, in <module>
    result = s.sort()
             ^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/series/series.py", line 3148, in sort
    self._s.sort(descending, nulls_last, multithreaded)
polars.exceptions.InvalidOperationError: `arg_sort_multiple` operation not supported for dtype `null

Expected behavior

Sorting should complete successfully.

Installed versions

main

Ah, can be a trivial clone in that case.