forked from rapidsai/cudf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests covering magic methods of Expr objects (rapidsai#15996)
repr is not stable for now because the pylibcudf datatype repr is not stable (it includes the address). Authors: - Lawrence Mitchell (https://github.com/wence-) Approvers: - Bradley Dice (https://github.com/bdice) URL: rapidsai#15996
- Loading branch information
Showing
3 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
__all__: list[str] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import cudf._lib.pylibcudf as plc | ||
|
||
from cudf_polars.dsl import expr | ||
|
||
|
||
def test_expression_equality_not_expression(): | ||
col = expr.Col(plc.DataType(plc.TypeId.INT8), "a") | ||
assert not (col == "a") # noqa: SIM201 | ||
assert col != "a" | ||
|
||
|
||
@pytest.mark.parametrize("dtype", [plc.TypeId.INT8, plc.TypeId.INT16]) | ||
def test_column_ne_dtypes_differ(dtype): | ||
a = expr.Col(plc.DataType(dtype), "a") | ||
b = expr.Col(plc.DataType(plc.TypeId.FLOAT32), "a") | ||
assert a != b | ||
|
||
|
||
@pytest.mark.parametrize("dtype", [plc.TypeId.INT8, plc.TypeId.INT16]) | ||
def test_column_ne_names_differ(dtype): | ||
a = expr.Col(plc.DataType(dtype), "a") | ||
b = expr.Col(plc.DataType(dtype), "b") | ||
assert a != b | ||
|
||
|
||
@pytest.mark.parametrize("dtype", [plc.TypeId.INT8, plc.TypeId.INT16]) | ||
def test_column_eq_names_eq(dtype): | ||
a = expr.Col(plc.DataType(dtype), "a") | ||
b = expr.Col(plc.DataType(dtype), "a") | ||
assert a == b | ||
|
||
|
||
def test_expr_hashable(): | ||
a = expr.Col(plc.DataType(plc.TypeId.INT8), "a") | ||
b = expr.Col(plc.DataType(plc.TypeId.INT8), "b") | ||
c = expr.Col(plc.DataType(plc.TypeId.FLOAT32), "c") | ||
|
||
collection = {a, b, c} | ||
assert len(collection) == 3 | ||
assert a in collection | ||
assert b in collection | ||
assert c in collection | ||
|
||
|
||
def test_namedexpr_hashable(): | ||
b = expr.NamedExpr("b", expr.Col(plc.DataType(plc.TypeId.INT8), "a")) | ||
c = expr.NamedExpr("c", expr.Col(plc.DataType(plc.TypeId.INT8), "a")) | ||
|
||
collection = {b, c} | ||
|
||
assert len(collection) == 2 | ||
|
||
assert b in collection | ||
assert c in collection | ||
|
||
|
||
def test_namedexpr_ne_values(): | ||
b1 = expr.NamedExpr("b1", expr.Col(plc.DataType(plc.TypeId.INT8), "a")) | ||
b2 = expr.NamedExpr("b2", expr.Col(plc.DataType(plc.TypeId.INT16), "a")) | ||
|
||
assert b1 != b2 | ||
|
||
|
||
@pytest.mark.xfail(reason="pylibcudf datatype repr not stable") | ||
def test_namedexpr_repr_stable(): | ||
b1 = expr.NamedExpr("b1", expr.Col(plc.DataType(plc.TypeId.INT8), "a")) | ||
b2 = expr.NamedExpr("b1", expr.Col(plc.DataType(plc.TypeId.INT8), "a")) | ||
|
||
assert repr(b1) == repr(b2) |