Skip to content

Commit

Permalink
lint and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Feb 21, 2024
1 parent 35e88fc commit 4510103
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions crates/polars-utils/src/total_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ macro_rules! impl_to_total_ord_wrapped {
impl_to_total_ord_wrapped!(f32);
impl_to_total_ord_wrapped!(f64);

/// This is safe without needing to map the option value to TotalOrdWrap, since
/// for example:
/// TotalOrdWrap<Option<T>> implements Eq + Hash, iff:
/// Option<T> implements TotalEq + TotalHash, iff:
/// T implements TotalEq + TotalHash
impl<T: Send + Sync + Copy> ToTotalOrd for Option<T> {
type TotalOrdItem = TotalOrdWrap<Option<T>>;
type SourceItem = Option<T>;
Expand Down
21 changes: 11 additions & 10 deletions py-polars/tests/unit/datatypes/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_unique(s: pl.Series, expect: pl.Series) -> None:
out = s.unique()
assert_series_equal(expect, out)

out = s.n_unique()
out = s.n_unique() # type: ignore[assignment]
assert expect.len() == out

out = s.gather(s.arg_unique()).sort()
Expand Down Expand Up @@ -138,6 +138,7 @@ def test_group_by() -> None:
)

expect = pl.Series("index", [[0, 1], [2, 3], [4], [5]], dtype=pl.List(pl.UInt32))
expect_no_null = expect.head(3)

for group_keys in (("x",), ("x", "a")):
for maintain_order in (True, False):
Expand All @@ -147,17 +148,17 @@ def test_group_by() -> None:
out = out.drop_nulls()

out = (
out.group_by(group_keys, maintain_order=maintain_order)
out.group_by(group_keys, maintain_order=maintain_order) # type: ignore[assignment]
.agg("index")
.sort(pl.col("index").list.get(0))
.select("index")
.to_series()
)

if drop_nulls:
assert_series_equal(expect.head(3), out)
assert_series_equal(expect_no_null, out) # type: ignore[arg-type]
else:
assert_series_equal(expect, out)
assert_series_equal(expect, out) # type: ignore[arg-type]


def test_joins() -> None:
Expand Down Expand Up @@ -195,20 +196,20 @@ def test_joins() -> None:
):
how = "left"
expect = pl.Series("rhs", [True, True, True, True, None, None])
out = df.join(rhs, on=join_on, how=how).sort("index").select("rhs").to_series()
out = df.join(rhs, on=join_on, how=how).sort("index").select("rhs").to_series() # type: ignore[arg-type]
assert_series_equal(expect, out)

how = "inner"
expect = pl.Series("index", [0, 1, 2, 3], dtype=pl.UInt32)
out = (
df.join(rhs, on=join_on, how=how).sort("index").select("index").to_series()
df.join(rhs, on=join_on, how=how).sort("index").select("index").to_series() # type: ignore[arg-type]
)
assert_series_equal(expect, out)

how = "outer"
expect = pl.Series("rhs", [True, True, True, True, None, None, True])
out = (
df.join(rhs, on=join_on, how=how)
df.join(rhs, on=join_on, how=how) # type: ignore[arg-type]
.sort("index", nulls_last=True)
.select("rhs")
.to_series()
Expand All @@ -218,7 +219,7 @@ def test_joins() -> None:
how = "semi"
expect = pl.Series("x", [-0.0, 0.0, float("-nan"), float("nan")])
out = (
df.join(rhs, on=join_on, how=how)
df.join(rhs, on=join_on, how=how) # type: ignore[arg-type]
.sort("index", nulls_last=True)
.select("x")
.to_series()
Expand All @@ -228,7 +229,7 @@ def test_joins() -> None:
how = "anti"
expect = pl.Series("x", [1.0, None])
out = (
df.join(rhs, on=join_on, how=how)
df.join(rhs, on=join_on, how=how) # type: ignore[arg-type]
.sort("index", nulls_last=True)
.select("x")
.to_series()
Expand All @@ -237,7 +238,7 @@ def test_joins() -> None:

# test asof
# note that nans never join because nans are always greater than the other
# side of the comparison (in this case the tolerance)
# side of the comparison (i.e. NaN > tolerance)
expect = pl.Series("rhs", [True, True, None, None, None, None])
out = (
df.sort("x")
Expand Down

0 comments on commit 4510103

Please sign in to comment.