Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 7, 2025
1 parent 676008f commit 02f67ab
Show file tree
Hide file tree
Showing 105 changed files with 299 additions and 1,109 deletions.
30 changes: 6 additions & 24 deletions tests/expr_and_series/all_horizontal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
@pytest.mark.parametrize("expr1", ["a", nw.col("a")])
@pytest.mark.parametrize("expr2", ["b", nw.col("b")])
def test_allh(constructor: Constructor, expr1: Any, expr2: Any) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
}
data = {"a": [False, False, True], "b": [False, True, True]}
df = nw.from_native(constructor(data))
result = df.select(all=nw.all_horizontal(expr1, expr2))

Expand All @@ -26,10 +23,7 @@ def test_allh(constructor: Constructor, expr1: Any, expr2: Any) -> None:


def test_allh_series(constructor_eager: ConstructorEager) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
}
data = {"a": [False, False, True], "b": [False, True, True]}
df = nw.from_native(constructor_eager(data), eager_only=True)
result = df.select(all=nw.all_horizontal(df["a"], df["b"]))

Expand All @@ -38,10 +32,7 @@ def test_allh_series(constructor_eager: ConstructorEager) -> None:


def test_allh_all(constructor: Constructor) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
}
data = {"a": [False, False, True], "b": [False, True, True]}
df = nw.from_native(constructor(data))
result = df.select(all=nw.all_horizontal(nw.all()))
expected = {"all": [False, False, True]}
Expand All @@ -51,18 +42,12 @@ def test_allh_all(constructor: Constructor) -> None:
assert_equal_data(result, expected)


def test_allh_nth(
constructor: Constructor,
request: pytest.FixtureRequest,
) -> None:
def test_allh_nth(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "polars" in str(constructor) and POLARS_VERSION < (1, 0):
request.applymarker(pytest.mark.xfail)
if "duckdb" in str(constructor):
request.applymarker(pytest.mark.xfail)
data = {
"a": [False, False, True],
"b": [False, True, True],
}
data = {"a": [False, False, True], "b": [False, True, True]}
df = nw.from_native(constructor(data))
result = df.select(nw.all_horizontal(nw.nth(0, 1)))
expected = {"a": [False, False, True]}
Expand All @@ -73,10 +58,7 @@ def test_allh_nth(


def test_horizontal_expressions_empty(constructor: Constructor) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
}
data = {"a": [False, False, True], "b": [False, True, True]}
df = nw.from_native(constructor(data))
with pytest.raises(
ValueError, match=r"At least one expression must be passed.*all_horizontal"
Expand Down
10 changes: 2 additions & 8 deletions tests/expr_and_series/any_horizontal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
@pytest.mark.parametrize("expr1", ["a", nw.col("a")])
@pytest.mark.parametrize("expr2", ["b", nw.col("b")])
def test_anyh(constructor: Constructor, expr1: Any, expr2: Any) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
}
data = {"a": [False, False, True], "b": [False, True, True]}
df = nw.from_native(constructor(data))
result = df.select(any=nw.any_horizontal(expr1, expr2))

Expand All @@ -24,10 +21,7 @@ def test_anyh(constructor: Constructor, expr1: Any, expr2: Any) -> None:


def test_anyh_all(constructor: Constructor) -> None:
data = {
"a": [False, False, True],
"b": [False, True, True],
}
data = {"a": [False, False, True], "b": [False, True, True]}
df = nw.from_native(constructor(data))
result = df.select(any=nw.any_horizontal(nw.all()))
expected = {"any": [False, True, True]}
Expand Down
6 changes: 2 additions & 4 deletions tests/expr_and_series/arithmetic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ def test_truediv_same_dims(

@pytest.mark.slow
@given( # type: ignore[misc]
left=st.integers(-100, 100),
right=st.integers(-100, 100),
left=st.integers(-100, 100), right=st.integers(-100, 100)
)
@pytest.mark.skipif(PANDAS_VERSION < (2, 0), reason="convert_dtypes not available")
def test_floordiv(left: int, right: int) -> None:
Expand Down Expand Up @@ -199,8 +198,7 @@ def test_floordiv(left: int, right: int) -> None:

@pytest.mark.slow
@given( # type: ignore[misc]
left=st.integers(-100, 100),
right=st.integers(-100, 100),
left=st.integers(-100, 100), right=st.integers(-100, 100)
)
@pytest.mark.skipif(PANDAS_VERSION < (2, 0), reason="convert_dtypes not available")
def test_mod(left: int, right: int) -> None:
Expand Down
13 changes: 3 additions & 10 deletions tests/expr_and_series/cast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@


@pytest.mark.filterwarnings("ignore:casting period[M] values to int64:FutureWarning")
def test_cast(
constructor: Constructor,
request: pytest.FixtureRequest,
) -> None:
def test_cast(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "duckdb" in str(constructor):
request.applymarker(pytest.mark.xfail)
if "pyarrow_table_constructor" in str(constructor) and PYARROW_VERSION <= (
Expand Down Expand Up @@ -112,8 +109,7 @@ def test_cast(


def test_cast_series(
constructor_eager: ConstructorEager,
request: pytest.FixtureRequest,
constructor_eager: ConstructorEager, request: pytest.FixtureRequest
) -> None:
if "pyarrow_table_constructor" in str(constructor_eager) and PYARROW_VERSION <= (
15,
Expand Down Expand Up @@ -237,10 +233,7 @@ def test_cast_struct(request: pytest.FixtureRequest, constructor: Constructor) -
request.applymarker(pytest.mark.xfail)

data = {
"a": [
{"movie": "Cars", "rating": 4.5},
{"movie": "Toy Story", "rating": 4.9},
]
"a": [{"movie": "Cars", "rating": 4.5}, {"movie": "Toy Story", "rating": 4.9}]
}

dtype = nw.Struct([nw.Field("movie", nw.String()), nw.Field("rating", nw.Float64())])
Expand Down
3 changes: 1 addition & 2 deletions tests/expr_and_series/cat/get_categories_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@


def test_get_categories(
request: pytest.FixtureRequest,
constructor_eager: ConstructorEager,
request: pytest.FixtureRequest, constructor_eager: ConstructorEager
) -> None:
if "pyarrow_table" in str(constructor_eager) and PYARROW_VERSION < (15, 0, 0):
request.applymarker(pytest.mark.xfail)
Expand Down
12 changes: 2 additions & 10 deletions tests/expr_and_series/concat_str_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
from tests.utils import Constructor
from tests.utils import assert_equal_data

data = {
"a": [1, 2, 3],
"b": ["dogs", "cats", None],
"c": ["play", "swim", "walk"],
}
data = {"a": [1, 2, 3], "b": ["dogs", "cats", None], "c": ["play", "swim", "walk"]}


@pytest.mark.parametrize(
Expand All @@ -34,11 +30,7 @@ def test_concat_str(
df.select(
"a",
nw.concat_str(
[
nw.col("a") * 2,
nw.col("b"),
nw.col("c"),
],
[nw.col("a") * 2, nw.col("b"), nw.col("c")],
separator=" ",
ignore_nulls=ignore_nulls, # default behavior is False
).alias("full_sentence"),
Expand Down
6 changes: 2 additions & 4 deletions tests/expr_and_series/convert_time_zone_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@


def test_convert_time_zone(
constructor: Constructor,
request: pytest.FixtureRequest,
constructor: Constructor, request: pytest.FixtureRequest
) -> None:
if (
("pyarrow" in str(constructor) and is_windows())
Expand Down Expand Up @@ -48,8 +47,7 @@ def test_convert_time_zone(


def test_convert_time_zone_series(
constructor_eager: ConstructorEager,
request: pytest.FixtureRequest,
constructor_eager: ConstructorEager, request: pytest.FixtureRequest
) -> None:
if (
("pyarrow" in str(constructor_eager) and is_windows())
Expand Down
17 changes: 4 additions & 13 deletions tests/expr_and_series/cum_count_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

data = {"a": ["x", "y", None, "z"]}

expected = {
"cum_count": [1, 2, 2, 3],
"reverse_cum_count": [3, 2, 1, 1],
}
expected = {"cum_count": [1, 2, 2, 3], "reverse_cum_count": [3, 2, 1, 1]}


@pytest.mark.parametrize("reverse", [True, False])
Expand All @@ -26,21 +23,15 @@ def test_cum_count_expr(

name = "reverse_cum_count" if reverse else "cum_count"
df = nw.from_native(constructor(data))
result = df.select(
nw.col("a").cum_count(reverse=reverse).alias(name),
)
result = df.select(nw.col("a").cum_count(reverse=reverse).alias(name))

assert_equal_data(result, {name: expected[name]})


def test_cum_count_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)
result = df.select(
cum_count=df["a"].cum_count(),
reverse_cum_count=df["a"].cum_count(reverse=True),
cum_count=df["a"].cum_count(), reverse_cum_count=df["a"].cum_count(reverse=True)
)
expected = {
"cum_count": [1, 2, 2, 3],
"reverse_cum_count": [3, 2, 1, 1],
}
expected = {"cum_count": [1, 2, 2, 3], "reverse_cum_count": [3, 2, 1, 1]}
assert_equal_data(result, expected)
12 changes: 3 additions & 9 deletions tests/expr_and_series/cum_max_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

data = {"a": [1, 3, None, 2]}

expected = {
"cum_max": [1, 3, None, 3],
"reverse_cum_max": [3, 3, None, 2],
}
expected = {"cum_max": [1, 3, None, 3], "reverse_cum_max": [3, 3, None, 2]}


@pytest.mark.parametrize("reverse", [True, False])
Expand All @@ -36,9 +33,7 @@ def test_cum_max_expr(

name = "reverse_cum_max" if reverse else "cum_max"
df = nw.from_native(constructor(data))
result = df.select(
nw.col("a").cum_max(reverse=reverse).alias(name),
)
result = df.select(nw.col("a").cum_max(reverse=reverse).alias(name))

assert_equal_data(result, {name: expected[name]})

Expand All @@ -56,7 +51,6 @@ def test_cum_max_series(

df = nw.from_native(constructor_eager(data), eager_only=True)
result = df.select(
cum_max=df["a"].cum_max(),
reverse_cum_max=df["a"].cum_max(reverse=True),
cum_max=df["a"].cum_max(), reverse_cum_max=df["a"].cum_max(reverse=True)
)
assert_equal_data(result, expected)
12 changes: 3 additions & 9 deletions tests/expr_and_series/cum_min_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

data = {"a": [3, 1, None, 2]}

expected = {
"cum_min": [3, 1, None, 1],
"reverse_cum_min": [1, 1, None, 2],
}
expected = {"cum_min": [3, 1, None, 1], "reverse_cum_min": [1, 1, None, 2]}


@pytest.mark.parametrize("reverse", [True, False])
Expand All @@ -36,9 +33,7 @@ def test_cum_min_expr(

name = "reverse_cum_min" if reverse else "cum_min"
df = nw.from_native(constructor(data))
result = df.select(
nw.col("a").cum_min(reverse=reverse).alias(name),
)
result = df.select(nw.col("a").cum_min(reverse=reverse).alias(name))

assert_equal_data(result, {name: expected[name]})

Expand All @@ -56,7 +51,6 @@ def test_cum_min_series(

df = nw.from_native(constructor_eager(data), eager_only=True)
result = df.select(
cum_min=df["a"].cum_min(),
reverse_cum_min=df["a"].cum_min(reverse=True),
cum_min=df["a"].cum_min(), reverse_cum_min=df["a"].cum_min(reverse=True)
)
assert_equal_data(result, expected)
12 changes: 3 additions & 9 deletions tests/expr_and_series/cum_prod_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

data = {"a": [1, 2, None, 3]}

expected = {
"cum_prod": [1, 2, None, 6],
"reverse_cum_prod": [6, 6, None, 3],
}
expected = {"cum_prod": [1, 2, None, 6], "reverse_cum_prod": [6, 6, None, 3]}


@pytest.mark.parametrize("reverse", [True, False])
Expand All @@ -36,9 +33,7 @@ def test_cum_prod_expr(

name = "reverse_cum_prod" if reverse else "cum_prod"
df = nw.from_native(constructor(data))
result = df.select(
nw.col("a").cum_prod(reverse=reverse).alias(name),
)
result = df.select(nw.col("a").cum_prod(reverse=reverse).alias(name))

assert_equal_data(result, {name: expected[name]})

Expand All @@ -56,7 +51,6 @@ def test_cum_prod_series(

df = nw.from_native(constructor_eager(data), eager_only=True)
result = df.select(
cum_prod=df["a"].cum_prod(),
reverse_cum_prod=df["a"].cum_prod(reverse=True),
cum_prod=df["a"].cum_prod(), reverse_cum_prod=df["a"].cum_prod(reverse=True)
)
assert_equal_data(result, expected)
12 changes: 3 additions & 9 deletions tests/expr_and_series/cum_sum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
from tests.utils import assert_equal_data

data = {"a": [1, 2, None, 4]}
expected = {
"cum_sum": [1, 3, None, 7],
"reverse_cum_sum": [7, 6, None, 4],
}
expected = {"cum_sum": [1, 3, None, 7], "reverse_cum_sum": [7, 6, None, 4]}


@pytest.mark.parametrize("reverse", [True, False])
Expand All @@ -25,17 +22,14 @@ def test_cum_sum_expr(

name = "reverse_cum_sum" if reverse else "cum_sum"
df = nw.from_native(constructor(data))
result = df.select(
nw.col("a").cum_sum(reverse=reverse).alias(name),
)
result = df.select(nw.col("a").cum_sum(reverse=reverse).alias(name))

assert_equal_data(result, {name: expected[name]})


def test_cum_sum_series(constructor_eager: ConstructorEager) -> None:
df = nw.from_native(constructor_eager(data), eager_only=True)
result = df.select(
cum_sum=df["a"].cum_sum(),
reverse_cum_sum=df["a"].cum_sum(reverse=True),
cum_sum=df["a"].cum_sum(), reverse_cum_sum=df["a"].cum_sum(reverse=True)
)
assert_equal_data(result, expected)
14 changes: 3 additions & 11 deletions tests/expr_and_series/diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@
from tests.utils import ConstructorEager
from tests.utils import assert_equal_data

data = {
"i": [0, 1, 2, 3, 4],
"b": [1, 2, 3, 5, 3],
"c": [5, 4, 3, 2, 1],
}
data = {"i": [0, 1, 2, 3, 4], "b": [1, 2, 3, 5, 3], "c": [5, 4, 3, 2, 1]}


def test_diff(
constructor: Constructor,
request: pytest.FixtureRequest,
) -> None:
def test_diff(constructor: Constructor, request: pytest.FixtureRequest) -> None:
if "pyarrow_table_constructor" in str(constructor) and PYARROW_VERSION < (13,):
# pc.pairwisediff is available since pyarrow 13.0.0
request.applymarker(pytest.mark.xfail)
Expand All @@ -36,8 +29,7 @@ def test_diff(


def test_diff_series(
constructor_eager: ConstructorEager,
request: pytest.FixtureRequest,
constructor_eager: ConstructorEager, request: pytest.FixtureRequest
) -> None:
if "pyarrow_table_constructor" in str(constructor_eager) and PYARROW_VERSION < (13,):
# pc.pairwisediff is available since pyarrow 13.0.0
Expand Down
Loading

0 comments on commit 02f67ab

Please sign in to comment.