Skip to content

Commit

Permalink
test: Add tests for various open issues that have been fixed (#20680)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemanley authored Jan 13, 2025
1 parent dd9a180 commit 0c3c89a
Showing 5 changed files with 72 additions and 0 deletions.
9 changes: 9 additions & 0 deletions py-polars/tests/unit/datatypes/test_struct.py
Original file line number Diff line number Diff line change
@@ -1217,3 +1217,12 @@ def test_struct_field_list_eval_17356() -> None:
@pytest.mark.parametrize("data", [[1], [[1]], {"a": 1}, [{"a": 1}]])
def test_leaf_list_eq_19613(data: Any) -> None:
assert not pl.DataFrame([data]).equals(pl.DataFrame([[data]]))


def test_nested_object_raises_15237() -> None:
obj = object()
df = pl.DataFrame({"a": [obj]})
with pytest.raises(
pl.exceptions.InvalidOperationError, match="nested objects are not allowed"
):
df.select(pl.struct("a"))
15 changes: 15 additions & 0 deletions py-polars/tests/unit/io/test_csv.py
Original file line number Diff line number Diff line change
@@ -2486,3 +2486,18 @@ def test_csv_compressed_new_columns_19916() -> None:

q = pl.scan_csv(b, has_header=False, new_columns=["a", "b", "c", "d", "e", "f"])
assert_frame_equal(q.collect(), df)


def test_trailing_separator_8240() -> None:
csv = "A|B|"

expected = pl.DataFrame(
{"column_1": ["A"], "column_2": ["B"], "column_3": [None]},
schema={"column_1": pl.String, "column_2": pl.String, "column_3": pl.String},
)

result = pl.read_csv(io.StringIO(csv), separator="|", has_header=False)
assert_frame_equal(result, expected)

result = pl.scan_csv(io.StringIO(csv), separator="|", has_header=False).collect()
assert_frame_equal(result, expected)
5 changes: 5 additions & 0 deletions py-polars/tests/unit/operations/test_is_sorted.py
Original file line number Diff line number Diff line change
@@ -422,3 +422,8 @@ def test_is_sorted_chunked_select() -> None:
.set_sorted("a")
.select(pl.col("a").alias("b"))
)["b"].flags["SORTED_ASC"]


def test_is_sorted_arithmetic_overflow_14106() -> None:
s = pl.Series([0, 200], dtype=pl.UInt8).sort()
assert not (s + 200).is_sorted()
30 changes: 30 additions & 0 deletions py-polars/tests/unit/operations/test_pivot.py
Original file line number Diff line number Diff line change
@@ -285,6 +285,36 @@ def test_pivot_index_struct_14101() -> None:
assert_frame_equal(result, expected)


def test_pivot_nested_struct_17065() -> None:
df = pl.DataFrame(
{
"foo": ["one", "two", "one", "two"],
"bar": ["x", "x", "y", "y"],
"baz": [
{"a": 1, "b": {"c": 2}},
{"a": 3, "b": {"c": 4}},
{"a": 5, "b": {"c": 6}},
{"a": 7, "b": {"c": 8}},
],
}
)
result = df.pivot(on="bar", index="foo", values="baz")
expected = pl.DataFrame(
{
"foo": ["one", "two"],
"x": [
{"a": 1, "b": {"c": 2}},
{"a": 3, "b": {"c": 4}},
],
"y": [
{"a": 5, "b": {"c": 6}},
{"a": 7, "b": {"c": 8}},
],
}
)
assert_frame_equal(result, expected)


def test_pivot_name_already_exists() -> None:
# This should be extremely rare...but still, good to check it
df = pl.DataFrame(
13 changes: 13 additions & 0 deletions py-polars/tests/unit/operations/unique/test_unique.py
Original file line number Diff line number Diff line change
@@ -257,3 +257,16 @@ def test_predicate_pushdown_unique() -> None:
print(q.filter(pl.col("id").is_in([1, 2, 3])).explain())
assert not q.filter(pl.col("id").is_in([1, 2, 3])).explain().startswith("FILTER")
assert q.filter(pl.col("id").sum() == pl.col("id")).explain().startswith("FILTER")


def test_unique_enum_19338() -> None:
for data in [
{"enum": ["A"]},
[{"enum": "A"}],
]:
df = pl.DataFrame(data, schema={"enum": pl.Enum(["A", "B", "C"])})
result = df.select(pl.col("enum").unique())
expected = pl.DataFrame(
{"enum": ["A"]}, schema={"enum": pl.Enum(["A", "B", "C"])}
)
assert_frame_equal(result, expected)

0 comments on commit 0c3c89a

Please sign in to comment.