Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jun 5, 2024
1 parent c801b2f commit 0dbc984
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions py-polars/tests/unit/operations/test_top_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,34 @@ def test_top_k_empty() -> None:
df = pl.DataFrame({"test": []})

assert_frame_equal(df.select([pl.col("test").top_k(2)]), df)


def test_top_k_nulls() -> None:
s = pl.Series([1, 2, 3, None, None])

valid_count = s.len() - s.null_count()
result = s.top_k(valid_count)
assert result.null_count() == 0

result = s.top_k(s.len())
assert result.null_count() == s.null_count()

result = s.top_k(s.len() * 2)
assert_series_equal(result.sort(), s.sort())


@pytest.mark.xfail(
reason="Currently bugged, see: https://github.com/pola-rs/polars/issues/15238"
)
def test_bottom_k_nulls() -> None:
s = pl.Series([1, 2, 3, None, None])
valid_count = s.len() - s.null_count()

result = s.bottom_k(valid_count)
assert result.null_count() == 0

result = s.bottom_k(s.len())
assert result.null_count() == s.null_count()

result = s.bottom_k(s.len() * 2)
assert_series_equal(result.sort(), s.sort())

0 comments on commit 0dbc984

Please sign in to comment.