Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable more lazy tests #663

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/expr_and_series/name/keep_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_keep_after_alias(constructor: Any) -> None:
compare_dicts(result, expected)


def test_keep_raise_anonymous(constructor_eager: Any) -> None:
df_raw = constructor_eager(data)
def test_keep_raise_anonymous(constructor: Any) -> None:
df_raw = constructor(data)
df = nw.from_native(df_raw)

context = (
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/name/map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def test_map_after_alias(constructor: Any) -> None:
compare_dicts(result, expected)


def test_map_raise_anonymous(constructor_eager: Any) -> None:
df_raw = constructor_eager(data)
def test_map_raise_anonymous(constructor: Any) -> None:
df_raw = constructor(data)
df = nw.from_native(df_raw)

context = (
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/name/prefix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def test_suffix_after_alias(constructor: Any) -> None:
compare_dicts(result, expected)


def test_prefix_raise_anonymous(constructor_eager: Any) -> None:
df_raw = constructor_eager(data)
def test_prefix_raise_anonymous(constructor: Any) -> None:
df_raw = constructor(data)
df = nw.from_native(df_raw)

context = (
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/name/suffix_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def test_suffix_after_alias(constructor: Any) -> None:
compare_dicts(result, expected)


def test_suffix_raise_anonymous(constructor_eager: Any) -> None:
df_raw = constructor_eager(data)
def test_suffix_raise_anonymous(constructor: Any) -> None:
df_raw = constructor(data)
df = nw.from_native(df_raw)

context = (
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/name/to_lowercase_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_to_lowercase_after_alias(constructor: Any) -> None:
compare_dicts(result, expected)


def test_to_lowercase_raise_anonymous(constructor_eager: Any) -> None:
df_raw = constructor_eager(data)
def test_to_lowercase_raise_anonymous(constructor: Any) -> None:
df_raw = constructor(data)
df = nw.from_native(df_raw)

context = (
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/name/to_uppercase_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_to_uppercase_after_alias(constructor: Any) -> None:
compare_dicts(result, expected)


def test_to_uppercase_raise_anonymous(constructor_eager: Any) -> None:
df_raw = constructor_eager(data)
def test_to_uppercase_raise_anonymous(constructor: Any) -> None:
df_raw = constructor(data)
df = nw.from_native(df_raw)

context = (
Expand Down
6 changes: 2 additions & 4 deletions tests/expr_and_series/sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ def test_expr_sample(constructor: Any) -> None:
assert result_series == expected_series


def test_expr_sample_fraction(constructor_eager: Any) -> None:
df = nw.from_native(
constructor_eager({"a": [1, 2, 3] * 10, "b": [4, 5, 6] * 10})
).lazy()
def test_expr_sample_fraction(constructor: Any) -> None:
df = nw.from_native(constructor({"a": [1, 2, 3] * 10, "b": [4, 5, 6] * 10})).lazy()

result_expr = df.select(nw.col("a").sample(fraction=0.1)).collect().shape
expected_expr = (3, 1)
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/sum_all_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def test_sum_all_expr(constructor: Any) -> None:
compare_dicts(result, expected)


def test_sum_all_namespace(constructor_eager: Any) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)
def test_sum_all_namespace(constructor: Any) -> None:
df = nw.from_native(constructor(data))
result = df.select(nw.sum("a", "b", "z"))
expected = {"a": [6], "b": [14], "z": [24.0]}
compare_dicts(result, expected)
16 changes: 14 additions & 2 deletions tests/expr_and_series/unary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ def test_unary(constructor: Any) -> None:
)
.select(nw.col("a_mean", "a_sum", "b_nunique", "z_min", "z_max").unique())
)
expected = {"a_mean": [2], "a_sum": [6], "b_nunique": [2], "z_min": [7], "z_max": [9]}
expected = {
"a_mean": [2],
"a_sum": [6],
"b_nunique": [2],
"z_min": [7],
"z_max": [9],
}
compare_dicts(result, expected)


Expand All @@ -31,5 +37,11 @@ def test_unary_series(constructor_eager: Any) -> None:
"z_min": [df["z"].min()],
"z_max": [df["z"].max()],
}
expected = {"a_mean": [2], "a_sum": [6], "b_nunique": [2], "z_min": [7], "z_max": [9]}
expected = {
"a_mean": [2],
"a_sum": [6],
"b_nunique": [2],
"z_min": [7],
"z_max": [9],
}
compare_dicts(result, expected)
4 changes: 2 additions & 2 deletions tests/frame/add_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from tests.utils import compare_dicts


def test_add(constructor_eager: Any) -> None:
def test_add(constructor: Any) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor_eager(data))
df = nw.from_native(constructor(data))
result = df.with_columns(
c=nw.col("a") + nw.col("b"),
d=nw.col("a") - nw.col("a").mean(),
Expand Down
4 changes: 2 additions & 2 deletions tests/frame/double_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from tests.utils import compare_dicts


def test_double(constructor_eager: Any) -> None:
def test_double(constructor: Any) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor_eager(data), eager_only=True)
df = nw.from_native(constructor(data))

result = df.with_columns(nw.all() * 2)
expected = {"a": [2, 6, 4], "b": [8, 8, 12], "z": [14.0, 16.0, 18.0]}
Expand Down
29 changes: 20 additions & 9 deletions tests/frame/join_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
from tests.utils import compare_dicts


def test_inner_join_two_keys(constructor_eager: Any) -> None:
def test_inner_join_two_keys(constructor: Any) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor_eager(data), eager_only=True)
df = nw.from_native(constructor(data))
df_right = df
result = df.lazy().join(
df_right.lazy(), left_on=["a", "b"], right_on=["a", "b"], how="inner"
)
expected = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9], "z_right": [7.0, 8, 9]}
expected = {
"a": [1, 3, 2],
"b": [4, 4, 6],
"z": [7.0, 8, 9],
"z_right": [7.0, 8, 9],
}
compare_dicts(result, expected)


Expand All @@ -37,11 +42,14 @@ def test_inner_join_single_key(constructor_eager: Any) -> None:
compare_dicts(result, expected)


def test_cross_join(constructor_eager: Any) -> None:
def test_cross_join(constructor: Any) -> None:
data = {"a": [1, 3, 2]}
df = nw.from_native(constructor_eager(data))
df = nw.from_native(constructor(data))
result = df.join(df, how="cross").sort("a", "a_right") # type: ignore[arg-type]
expected = {"a": [1, 1, 1, 2, 2, 2, 3, 3, 3], "a_right": [1, 2, 3, 1, 2, 3, 1, 2, 3]}
expected = {
"a": [1, 1, 1, 2, 2, 2, 3, 3, 3],
"a_right": [1, 2, 3, 1, 2, 3, 1, 2, 3],
}
compare_dicts(result, expected)

with pytest.raises(ValueError, match="Can not pass left_on, right_on for cross join"):
Expand All @@ -54,7 +62,10 @@ def test_cross_join_non_pandas() -> None:
# HACK to force testing for a non-pandas codepath
df._compliant_frame._implementation = Implementation.MODIN
result = df.join(df, how="cross") # type: ignore[arg-type]
expected = {"a": [1, 1, 1, 3, 3, 3, 2, 2, 2], "a_right": [1, 3, 2, 1, 3, 2, 1, 3, 2]}
expected = {
"a": [1, 1, 1, 3, 3, 3, 2, 2, 2],
"a_right": [1, 3, 2, 1, 3, 2, 1, 3, 2],
}
compare_dicts(result, expected)


Expand Down Expand Up @@ -101,9 +112,9 @@ def test_semi_join(


@pytest.mark.parametrize("how", ["right", "full"])
def test_join_not_implemented(constructor_eager: Any, how: str) -> None:
def test_join_not_implemented(constructor: Any, how: str) -> None:
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
df = nw.from_native(constructor_eager(data))
df = nw.from_native(constructor(data))

with pytest.raises(
NotImplementedError,
Expand Down
6 changes: 2 additions & 4 deletions tests/frame/series_sum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
from tests.utils import compare_dicts


def test_series_sum(constructor_eager: Any) -> None:
def test_series_sum(constructor: Any) -> None:
data = {
"a": [0, 1, 2, 3, 4],
"b": [1, 2, 3, 5, 3],
"c": [5, 4, None, 2, 1],
}
df = nw.from_native(
constructor_eager(data), strict=False, eager_only=True, allow_series=True
)
df = nw.from_native(constructor(data), strict=False, allow_series=True)

result = df.select(nw.col("a", "b", "c").sum())

Expand Down
3 changes: 2 additions & 1 deletion tests/frame/slice_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def test_slice_rows_with_step(request: Any, constructor_eager: Any) -> None:

def test_slice_rows_with_step_pyarrow() -> None:
with pytest.raises(
NotImplementedError, match="Slicing with step is not supported on PyArrow tables"
NotImplementedError,
match="Slicing with step is not supported on PyArrow tables",
):
nw.from_native(pa.table(data))[1::2]

Expand Down
8 changes: 4 additions & 4 deletions tests/frame/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def test_columns(constructor: Any) -> None:
assert result == expected


def test_expr_binary(constructor_eager: Any) -> None:
df_raw = constructor_eager(data)
def test_expr_binary(constructor: Any) -> None:
df_raw = constructor(data)
result = nw.from_native(df_raw).with_columns(
a=(1 + 3 * nw.col("a")) * (1 / nw.col("a")),
b=nw.col("z") / (2 - nw.col("b")),
Expand Down Expand Up @@ -67,8 +67,8 @@ def test_expr_binary(constructor_eager: Any) -> None:
compare_dicts(result, expected)


def test_expr_transform(constructor_eager: Any) -> None:
df = nw.from_native(constructor_eager(data))
def test_expr_transform(constructor: Any) -> None:
df = nw.from_native(constructor(data))
result = df.with_columns(a=nw.col("a").is_between(-1, 1), b=nw.col("b").is_in([4, 5]))
expected = {"a": [True, False, False], "b": [True, True, False], "z": [7, 8, 9]}
compare_dicts(result, expected)
Expand Down
4 changes: 2 additions & 2 deletions tests/frame/with_columns_sequence_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
}


def test_with_columns(constructor_eager: Any) -> None:
def test_with_columns(constructor: Any) -> None:
result = (
nw.from_native(constructor_eager(data))
nw.from_native(constructor(data))
.with_columns(d=np.array([4, 5]))
.with_columns(e=nw.col("d") + 1)
.select("d", "e")
Expand Down
4 changes: 2 additions & 2 deletions tests/series_only/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def test_is_in(constructor_eager: Any) -> None:
assert result[2]


def test_is_in_other(constructor_eager: Any) -> None:
df_raw = constructor_eager({"a": data})
def test_is_in_other(constructor: Any) -> None:
df_raw = constructor({"a": data})
with pytest.raises(
NotImplementedError,
match=(
Expand Down
Loading