From c506fb80926d2b93623f5b79bd8e03fd995e2e9e Mon Sep 17 00:00:00 2001 From: Luke Manley Date: Tue, 11 Feb 2025 06:06:51 -0500 Subject: [PATCH] test: Add tests for fixed open issues --- .../unit/operations/map/test_map_elements.py | 17 ++++++++++++++++- .../tests/unit/operations/test_fill_null.py | 11 +++++++++++ py-polars/tests/unit/operations/test_join.py | 13 +++++++++++++ .../tests/unit/streaming/test_streaming_io.py | 10 ++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/py-polars/tests/unit/operations/map/test_map_elements.py b/py-polars/tests/unit/operations/map/test_map_elements.py index c84afa93e24e..ea7e1b9405cb 100644 --- a/py-polars/tests/unit/operations/map/test_map_elements.py +++ b/py-polars/tests/unit/operations/map/test_map_elements.py @@ -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 @@ -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) diff --git a/py-polars/tests/unit/operations/test_fill_null.py b/py-polars/tests/unit/operations/test_fill_null.py index 1ab3a707fcda..90ac3ca3f92a 100644 --- a/py-polars/tests/unit/operations/test_fill_null.py +++ b/py-polars/tests/unit/operations/test_fill_null.py @@ -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]) diff --git a/py-polars/tests/unit/operations/test_join.py b/py-polars/tests/unit/operations/test_join.py index dd437b5e934a..ca3b8e849471 100644 --- a/py-polars/tests/unit/operations/test_join.py +++ b/py-polars/tests/unit/operations/test_join.py @@ -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) diff --git a/py-polars/tests/unit/streaming/test_streaming_io.py b/py-polars/tests/unit/streaming/test_streaming_io.py index 44627f0e19f3..23286c2f562e 100644 --- a/py-polars/tests/unit/streaming/test_streaming_io.py +++ b/py-polars/tests/unit/streaming/test_streaming_io.py @@ -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(), + )