Skip to content

Commit

Permalink
forgot to rename in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Feb 1, 2025
1 parent 6b8e919 commit 658347a
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions py-polars/tests/unit/operations/namespaces/list/test_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def test_list_pad_start_with_expr_fill() -> None:
{"a": [[1], [], [1, 2, 3]], "int": [0, 999, 2], "float": [0.0, 999, 2]}
)
result = df.select(
filled_int=pl.col("a").list.pad_start(fill_value=pl.col("int"), width=3),
filled_float=pl.col("a").list.pad_start(fill_value=pl.col("float"), width=1),
filled_int=pl.col("a").list.pad_start(fill_value=pl.col("int"), length=3),
filled_float=pl.col("a").list.pad_start(fill_value=pl.col("float"), length=1),
)
expected = pl.DataFrame(
{
Expand Down Expand Up @@ -53,67 +53,67 @@ def test_list_pad_start_with_expr_fill() -> None:
)
def test_list_pad_start_with_lit_fill(data: Any, fill_value: Any, expect: Any) -> None:
df = pl.DataFrame({"a": data})
result = df.select(pl.col("a").list.pad_start(fill_value, width=3))
result = df.select(pl.col("a").list.pad_start(fill_value, length=3))
expected = pl.DataFrame({"a": expect})
assert_frame_equal(result, expected)


def test_list_pad_start_no_slice() -> None:
df = pl.DataFrame({"a": [[1], [2, 3, 4, 5]]})
result = df.select(pl.col("a").list.pad_start(1, width=2))
result = df.select(pl.col("a").list.pad_start(1, length=2))
expected = pl.DataFrame(
{"a": [[1, 1], [2, 3, 4, 5]]}, schema={"a": pl.List(pl.Int64)}
)
assert_frame_equal(result, expected)


def test_list_pad_start_with_expr_width() -> None:
df = pl.DataFrame({"a": [[1], [], [1, 2, 3]], "width": [2, 2, 4]})
def test_list_pad_start_with_expr_length() -> None:
df = pl.DataFrame({"a": [[1], [], [1, 2, 3]], "length": [2, 2, 4]})
result = df.select(
width_expr=pl.col("a").list.pad_start(
fill_value=999, width=pl.col("a").list.len().max()
length_expr=pl.col("a").list.pad_start(
fill_value=999, length=pl.col("a").list.len().max()
),
width_col=pl.col("a").list.pad_start(fill_value=999, width=pl.col("width")),
length_col=pl.col("a").list.pad_start(fill_value=999, length=pl.col("length")),
)
expected = pl.DataFrame(
{
"width_expr": [[999, 999, 1], [999, 999, 999], [1, 2, 3]],
"width_col": [[999, 1], [999, 999], [999, 1, 2, 3]],
"length_expr": [[999, 999, 1], [999, 999, 999], [1, 2, 3]],
"length_col": [[999, 1], [999, 999], [999, 1, 2, 3]],
}
)
assert_frame_equal(result, expected)


def test_list_pad_start_zero_width() -> None:
def test_list_pad_start_zero_length() -> None:
df = pl.DataFrame({"a": [[1], [2, 3]]})
result = df.select(pl.col("a").list.pad_start(1, width=0))
result = df.select(pl.col("a").list.pad_start(1, length=0))
expected = pl.DataFrame({"a": [[1], [2, 3]]}, schema={"a": pl.List(pl.Int64)})
assert_frame_equal(result, expected)


def test_list_pad_start_casts_to_supertype() -> None:
df = pl.DataFrame({"a": [["a"], ["a", "b"]]})
result = df.select(pl.col("a").list.pad_start(1, width=2))
result = df.select(pl.col("a").list.pad_start(1, length=2))
expected = pl.DataFrame({"a": [["1", "a"], ["a", "b"]]})
assert_frame_equal(result, expected)

with pytest.raises(SchemaError, match="failed to determine supertype"):
pl.DataFrame({"a": [[]]}, schema={"a": pl.List(pl.Categorical)}).select(
pl.col("a").list.pad_start(True, width=2)
pl.col("a").list.pad_start(True, length=2)
)


def test_list_pad_start_errors() -> None:
df = pl.DataFrame({"a": [["a"], ["a", "b"]]})

with pytest.raises(TypeError, match="fill_value"):
df.select(pl.col("a").list.pad_start(width=2)) # type: ignore[call-arg]
df.select(pl.col("a").list.pad_start(length=2)) # type: ignore[call-arg]
with pytest.raises(InvalidOperationError, match="to String not supported"):
df.select(pl.col("a").list.pad_start(timedelta(days=1), width=2))
df.select(pl.col("a").list.pad_start(timedelta(days=1), length=2))
with pytest.raises(
InvalidOperationError, match="conversion from `i32` to `u64` failed"
):
df.select(pl.col("a").list.pad_start("foo", width=-1))
df.select(pl.col("a").list.pad_start("foo", length=-1))


@pytest.mark.parametrize(
Expand All @@ -127,4 +127,4 @@ def test_list_pad_start_errors() -> None:
def test_list_pad_start_unsupported_type(fill_value: Any, type: Any) -> None:
df = pl.DataFrame({"a": [[], []]}, schema={"a": pl.List(type)})
with pytest.raises(InvalidOperationError, match="doesn't work on data type"):
df.select(pl.col("a").list.pad_start(fill_value, width=2))
df.select(pl.col("a").list.pad_start(fill_value, length=2))

0 comments on commit 658347a

Please sign in to comment.