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

test: Add tests for fixed open issues #21185

Merged
merged 3 commits into from
Feb 15, 2025
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
17 changes: 16 additions & 1 deletion py-polars/tests/unit/operations/map/test_map_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
from datetime import date, datetime, timedelta
from typing import Any
from typing import Any, NamedTuple

import numpy as np
import pytest
Expand Down Expand Up @@ -384,3 +384,18 @@ def test_map_elements_list_return_dtype() -> None:
)
expected = pl.Series([[2], [3, 4]], dtype=return_dtype)
assert_series_equal(result, expected)


def test_map_elements_list_of_named_tuple_15425() -> None:
class Foo(NamedTuple):
x: int

df = pl.DataFrame({"a": [0, 1, 2]})
result = df.select(
pl.col("a").map_elements(
lambda x: [Foo(i) for i in range(x)],
return_dtype=pl.List(pl.Struct({"x": pl.Int64})),
)
)
expected = pl.DataFrame({"a": [[], [{"x": 0}], [{"x": 0}, {"x": 1}]]})
assert_frame_equal(result, expected)
11 changes: 11 additions & 0 deletions py-polars/tests/unit/operations/test_fill_null.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,14 @@ def test_fill_null_int_dtype_15546() -> None:
result = df.fill_null(0).collect()
expected = pl.Series("a", [1, 2, 0], dtype=pl.Int8).to_frame()
assert_frame_equal(result, expected)


def test_fill_null_with_list_10869() -> None:
assert_series_equal(
pl.Series([[1], None]).fill_null([2]),
pl.Series([[1], [2]]),
)

match = "failed to determine supertype"
with pytest.raises(pl.exceptions.SchemaError, match=match):
pl.Series([1, None]).fill_null([2])
13 changes: 13 additions & 0 deletions py-polars/tests/unit/operations/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -1700,3 +1700,16 @@ def test_join_on_struct() -> None:
c=pl.Series([4, 2, 4, 2, 4, 2]),
),
)


def test_empty_join_result_with_array_15474() -> None:
lhs = pl.DataFrame(
{
"x": [1, 2],
"y": pl.Series([[1, 2, 3], [4, 5, 6]], dtype=pl.Array(pl.Int64, 3)),
}
)
rhs = pl.DataFrame({"x": [0]})
result = lhs.join(rhs, on="x")
expected = pl.DataFrame(schema={"x": pl.Int64, "y": pl.Array(pl.Int64, 3)})
assert_frame_equal(result, expected)
10 changes: 10 additions & 0 deletions py-polars/tests/unit/streaming/test_streaming_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,13 @@ def test_nyi_scan_in_memory(method: str) -> None:
match="not yet implemented: Streaming scanning of in-memory buffers",
):
(getattr(pl, f"scan_{method}"))(f).collect(streaming=True)


def test_empty_sink_parquet_join_14863(tmp_path: Path) -> None:
file_path = tmp_path / "empty.parquet"
lf = pl.LazyFrame(schema=["a", "b", "c"]).cast(pl.String)
lf.sink_parquet(file_path)
assert_frame_equal(
pl.LazyFrame({"a": ["uno"]}).join(pl.scan_parquet(file_path), on="a").collect(),
lf.collect(),
)
Loading