Skip to content

Commit

Permalink
replace request:Any with pytest.FixtureRequest (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
raisadz authored Sep 13, 2024
1 parent fc6fb53 commit aacc3a3
Show file tree
Hide file tree
Showing 42 changed files with 100 additions and 69 deletions.
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def pyarrow_table_constructor(obj: Any) -> IntoDataFrame:


@pytest.fixture(params=eager_constructors)
def constructor_eager(request: Any) -> Callable[[Any], IntoDataFrame]:
def constructor_eager(request: pytest.FixtureRequest) -> Callable[[Any], IntoDataFrame]:
return request.param # type: ignore[no-any-return]


@pytest.fixture(params=[*eager_constructors, *lazy_constructors])
def constructor(request: Any) -> Callable[[Any], Any]:
def constructor(request: pytest.FixtureRequest) -> Callable[[Any], Any]:
return request.param # type: ignore[no-any-return]
2 changes: 1 addition & 1 deletion tests/expr_and_series/arg_true_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.utils import compare_dicts


def test_arg_true(constructor: Any, request: Any) -> None:
def test_arg_true(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor({"a": [1, None, None, 3]}))
Expand Down
12 changes: 7 additions & 5 deletions tests/expr_and_series/arithmetic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_arithmetic_expr(
rhs: Any,
expected: list[Any],
constructor: Any,
request: Any,
request: pytest.FixtureRequest,
) -> None:
if attr == "__mod__" and any(
x in str(constructor) for x in ["pandas_pyarrow", "modin"]
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_right_arithmetic_expr(
rhs: Any,
expected: list[Any],
constructor: Any,
request: Any,
request: pytest.FixtureRequest,
) -> None:
if attr == "__rmod__" and any(
x in str(constructor) for x in ["pandas_pyarrow", "modin"]
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_arithmetic_series(
rhs: Any,
expected: list[Any],
constructor_eager: Any,
request: Any,
request: pytest.FixtureRequest,
) -> None:
if attr == "__mod__" and any(
x in str(constructor_eager) for x in ["pandas_pyarrow", "modin"]
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_right_arithmetic_series(
rhs: Any,
expected: list[Any],
constructor_eager: Any,
request: Any,
request: pytest.FixtureRequest,
) -> None:
if attr == "__rmod__" and any(
x in str(constructor_eager) for x in ["pandas_pyarrow", "modin"]
Expand All @@ -137,7 +137,9 @@ def test_right_arithmetic_series(
compare_dicts(result, {"a": expected})


def test_truediv_same_dims(constructor_eager: Any, request: Any) -> None:
def test_truediv_same_dims(
constructor_eager: Any, request: pytest.FixtureRequest
) -> None:
if "polars" in str(constructor_eager):
# https://github.com/pola-rs/polars/issues/17760
request.applymarker(pytest.mark.xfail)
Expand Down
8 changes: 5 additions & 3 deletions tests/expr_and_series/cast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@


@pytest.mark.filterwarnings("ignore:casting period[M] values to int64:FutureWarning")
def test_cast(constructor: Any, request: Any) -> None:
def test_cast(constructor: Any, request: pytest.FixtureRequest) -> None:
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) <= (15,): # pragma: no cover
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_cast(constructor: Any, request: Any) -> None:
assert dict(result.collect_schema()) == expected


def test_cast_series(constructor: Any, request: Any) -> None:
def test_cast_series(constructor: Any, request: pytest.FixtureRequest) -> None:
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) <= (15,): # pragma: no cover
Expand Down Expand Up @@ -162,7 +162,9 @@ def test_cast_string() -> None:
assert str(result.dtype) in ("string", "object", "dtype('O')")


def test_cast_raises_for_unknown_dtype(constructor: Any, request: Any) -> None:
def test_cast_raises_for_unknown_dtype(
constructor: Any, request: pytest.FixtureRequest
) -> None:
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) <= (15,): # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/cat/get_categories_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
data = {"a": ["one", "two", "two"]}


def test_get_categories(request: Any, constructor_eager: Any) -> None:
def test_get_categories(request: pytest.FixtureRequest, constructor_eager: Any) -> None:
if "pyarrow_table" in str(constructor_eager) and parse_version(
pa.__version__
) < parse_version("15.0.0"):
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}


def test_diff(constructor: Any, request: Any) -> None:
def test_diff(constructor: Any, request: pytest.FixtureRequest) -> None:
if "pyarrow_table_constructor" in str(constructor) and parse_version(
pa.__version__
) < (13,):
Expand All @@ -31,7 +31,7 @@ def test_diff(constructor: Any, request: Any) -> None:
compare_dicts(result, expected)


def test_diff_series(constructor_eager: Any, request: Any) -> None:
def test_diff_series(constructor_eager: Any, request: pytest.FixtureRequest) -> None:
if "pyarrow_table_constructor" in str(constructor_eager) and parse_version(
pa.__version__
) < (13,):
Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/drop_nulls_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tests.utils import compare_dicts


def test_drop_nulls(constructor: Any, request: Any) -> None:
def test_drop_nulls(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
data = {
Expand Down
11 changes: 8 additions & 3 deletions tests/expr_and_series/dt/datetime_attributes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
)
def test_datetime_attributes(
request: Any, constructor: Any, attribute: str, expected: list[int]
request: pytest.FixtureRequest, constructor: Any, attribute: str, expected: list[int]
) -> None:
if (
attribute == "date"
Expand Down Expand Up @@ -67,7 +67,10 @@ def test_datetime_attributes(
],
)
def test_datetime_attributes_series(
request: Any, constructor_eager: Any, attribute: str, expected: list[int]
request: pytest.FixtureRequest,
constructor_eager: Any,
attribute: str,
expected: list[int],
) -> None:
if (
attribute == "date"
Expand All @@ -83,7 +86,9 @@ def test_datetime_attributes_series(
compare_dicts(result, {"a": expected})


def test_datetime_chained_attributes(request: Any, constructor_eager: Any) -> None:
def test_datetime_chained_attributes(
request: pytest.FixtureRequest, constructor_eager: Any
) -> None:
if "pandas" in str(constructor_eager) and "pyarrow" not in str(constructor_eager):
request.applymarker(pytest.mark.xfail)
if "cudf" in str(constructor_eager):
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/dt/datetime_duration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
],
)
def test_duration_attributes(
request: Any,
request: pytest.FixtureRequest,
constructor: Any,
attribute: str,
expected_a: list[int],
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_duration_attributes(
],
)
def test_duration_attributes_series(
request: Any,
request: pytest.FixtureRequest,
constructor_eager: Any,
attribute: str,
expected_a: list[int],
Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}


def test_filter(constructor: Any, request: Any) -> None:
def test_filter(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
Expand Down
4 changes: 3 additions & 1 deletion tests/expr_and_series/gather_every_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

@pytest.mark.parametrize("n", [1, 2, 3])
@pytest.mark.parametrize("offset", [1, 2, 3])
def test_gather_every_expr(constructor: Any, n: int, offset: int, request: Any) -> None:
def test_gather_every_expr(
constructor: Any, n: int, offset: int, request: pytest.FixtureRequest
) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/head_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.parametrize("n", [2, -1])
def test_head(constructor: Any, n: int, request: Any) -> None:
def test_head(constructor: Any, n: int, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "polars" in str(constructor) and n < 0:
Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/len_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_len_no_filter(constructor: Any) -> None:
compare_dicts(df, expected)


def test_len_chaining(constructor: Any, request: Any) -> None:
def test_len_chaining(constructor: Any, request: pytest.FixtureRequest) -> None:
data = {"a": list("xyz"), "b": [1, 2, 1]}
expected = {"a1": [2], "a2": [1]}
if "dask" in str(constructor):
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/mode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}


def test_mode_single_expr(constructor: Any, request: Any) -> None:
def test_mode_single_expr(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)

Expand All @@ -23,7 +23,7 @@ def test_mode_single_expr(constructor: Any, request: Any) -> None:
compare_dicts(result, expected)


def test_mode_multi_expr(constructor: Any, request: Any) -> None:
def test_mode_multi_expr(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor) or (
"polars" in str(constructor) and parse_version(pl.__version__) >= (1, 7, 0)
):
Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/over_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_over_multiple(constructor: Any) -> None:
compare_dicts(result, expected)


def test_over_invalid(request: Any, constructor: Any) -> None:
def test_over_invalid(request: pytest.FixtureRequest, constructor: Any) -> None:
if "polars" in str(constructor):
request.applymarker(pytest.mark.xfail)

Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/quantile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_quantile_expr(
constructor: Any,
interpolation: Literal["nearest", "higher", "lower", "midpoint", "linear"],
expected: dict[str, list[float]],
request: Any,
request: pytest.FixtureRequest,
) -> None:
if "dask" in str(constructor) and interpolation != "linear":
request.applymarker(pytest.mark.xfail)
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import narwhals.stable.v1 as nw


def test_expr_sample(constructor: Any, request: Any) -> None:
def test_expr_sample(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor({"a": [1, 2, 3], "b": [4, 5, 6]})).lazy()
Expand All @@ -19,7 +19,7 @@ def test_expr_sample(constructor: Any, request: Any) -> None:
assert result_series == expected_series


def test_expr_sample_fraction(constructor: Any, request: Any) -> None:
def test_expr_sample_fraction(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor({"a": [1, 2, 3] * 10, "b": [4, 5, 6] * 10})).lazy()
Expand Down
4 changes: 2 additions & 2 deletions tests/expr_and_series/str/to_uppercase_to_lowercase_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_str_to_uppercase(
constructor: Any,
data: dict[str, list[str]],
expected: dict[str, list[str]],
request: Any,
request: pytest.FixtureRequest,
) -> None:
df = nw.from_native(constructor(data))
result_frame = df.select(nw.col("a").str.to_uppercase())
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_str_to_uppercase_series(
constructor_eager: Any,
data: dict[str, list[str]],
expected: dict[str, list[str]],
request: Any,
request: pytest.FixtureRequest,
) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)

Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/tail_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.parametrize("n", [2, -1])
def test_head(constructor: Any, n: int, request: Any) -> None:
def test_head(constructor: Any, n: int, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "polars" in str(constructor) and n < 0:
Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/unary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.utils import compare_dicts


def test_unary(constructor: Any, request: Any) -> None:
def test_unary(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}
Expand Down
2 changes: 1 addition & 1 deletion tests/expr_and_series/unique_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
data = {"a": [1, 1, 2]}


def test_unique_expr(constructor: Any, request: Any) -> None:
def test_unique_expr(constructor: Any, request: pytest.FixtureRequest) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
df = nw.from_native(constructor(data))
Expand Down
10 changes: 6 additions & 4 deletions tests/expr_and_series/when_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_no_arg_when_fail(constructor: Any) -> None:
df.select(nw.when().then(value=3).alias("a_when"))


def test_value_numpy_array(request: Any, constructor: Any) -> None:
def test_value_numpy_array(request: pytest.FixtureRequest, constructor: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)

Expand Down Expand Up @@ -89,7 +89,7 @@ def test_value_expression(constructor: Any) -> None:
compare_dicts(result, expected)


def test_otherwise_numpy_array(request: Any, constructor: Any) -> None:
def test_otherwise_numpy_array(request: pytest.FixtureRequest, constructor: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)

Expand Down Expand Up @@ -117,7 +117,7 @@ def test_otherwise_series(constructor_eager: Any) -> None:
compare_dicts(result, expected)


def test_otherwise_expression(request: Any, constructor: Any) -> None:
def test_otherwise_expression(request: pytest.FixtureRequest, constructor: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)

Expand All @@ -131,7 +131,9 @@ def test_otherwise_expression(request: Any, constructor: Any) -> None:
compare_dicts(result, expected)


def test_when_then_otherwise_into_expr(request: Any, constructor: Any) -> None:
def test_when_then_otherwise_into_expr(
request: pytest.FixtureRequest, constructor: Any
) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)

Expand Down
10 changes: 7 additions & 3 deletions tests/frame/array_dunder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from tests.utils import compare_dicts


def test_array_dunder(request: Any, constructor_eager: Any) -> None:
def test_array_dunder(request: pytest.FixtureRequest, constructor_eager: Any) -> None:
if "pyarrow_table" in str(constructor_eager) and parse_version(
pa.__version__
) < parse_version("16.0.0"): # pragma: no cover
Expand All @@ -22,7 +22,9 @@ def test_array_dunder(request: Any, constructor_eager: Any) -> None:
np.testing.assert_array_equal(result, np.array([[1], [2], [3]], dtype="int64"))


def test_array_dunder_with_dtype(request: Any, constructor_eager: Any) -> None:
def test_array_dunder_with_dtype(
request: pytest.FixtureRequest, constructor_eager: Any
) -> None:
if "pyarrow_table" in str(constructor_eager) and parse_version(
pa.__version__
) < parse_version("16.0.0"): # pragma: no cover
Expand All @@ -33,7 +35,9 @@ def test_array_dunder_with_dtype(request: Any, constructor_eager: Any) -> None:
np.testing.assert_array_equal(result, np.array([[1], [2], [3]], dtype=object))


def test_array_dunder_with_copy(request: Any, constructor_eager: Any) -> None:
def test_array_dunder_with_copy(
request: pytest.FixtureRequest, constructor_eager: Any
) -> None:
if "pyarrow_table" in str(constructor_eager) and parse_version(pa.__version__) < (
16,
0,
Expand Down
2 changes: 1 addition & 1 deletion tests/frame/clone_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.utils import compare_dicts


def test_clone(request: Any, constructor: Any) -> None:
def test_clone(request: pytest.FixtureRequest, constructor: Any) -> None:
if "dask" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "pyarrow_table" in str(constructor):
Expand Down
Loading

0 comments on commit aacc3a3

Please sign in to comment.