Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Feb 21, 2024
1 parent 9178665 commit d5f324b
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions py-polars/tests/unit/datatypes/test_float.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import polars as pl
import pytest
from polars.testing import assert_series_equal, assert_frame_equal

import polars as pl
from polars.testing import assert_series_equal


def test_nan_in_group_by_agg() -> None:
Expand Down Expand Up @@ -38,7 +39,7 @@ def test_nan_aggregations() -> None:

@pytest.mark.parametrize(
("s", "expect"),
(
[
(
pl.Series(
"x",
Expand Down Expand Up @@ -67,7 +68,7 @@ def test_nan_aggregations() -> None:
),
pl.Series("x", [0.0, 1.0, float("nan")]),
),
),
],
)
def test_unique(s: pl.Series, expect: pl.Series) -> None:
out = s.unique()
Expand Down Expand Up @@ -117,6 +118,8 @@ def test_hash() -> None:

def test_group_by() -> None:
# Test num_groups_proxy
# * -0.0 and 0.0 in same groups
# * -nan and nan in same groups
df = (
pl.Series(
"x",
Expand Down Expand Up @@ -158,6 +161,7 @@ def test_group_by() -> None:


def test_joins() -> None:
# Test that -0.0 joins with 0.0 and nan joins with nan
df = (
pl.Series(
"x",
Expand All @@ -176,6 +180,7 @@ def test_joins() -> None:
)

for join_on in (
# Single and multiple keys
("x",),
(
"x",
Expand Down Expand Up @@ -229,3 +234,25 @@ def test_joins() -> None:
.to_series()
)
assert_series_equal(expect, out)


def test_first_last_distinct() -> None:
s = pl.Series(
"x",
[
-0.0,
0.0,
float("-nan"),
float("nan"),
1.0,
None,
],
)

assert_series_equal(
pl.Series("x", [True, False, True, False, True, True]), s.is_first_distinct()
)

assert_series_equal(
pl.Series("x", [False, True, False, True, True, True]), s.is_last_distinct()
)

0 comments on commit d5f324b

Please sign in to comment.