Skip to content

Commit bcf6753

Browse files
authored
test: Add various tests (#20768)
1 parent 672e4c6 commit bcf6753

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

py-polars/tests/unit/dataframe/test_serde.py

+7
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,10 @@ def test_df_serialize_invalid_type() -> None:
202202
ComputeError, match="serializing data of type Object is not supported"
203203
):
204204
df.serialize()
205+
206+
207+
def test_df_serde_list_of_null_17230() -> None:
208+
df = pl.Series([[]], dtype=pl.List(pl.Null)).to_frame()
209+
ser = df.serialize(format="json")
210+
result = pl.DataFrame.deserialize(io.StringIO(ser), format="json")
211+
assert_frame_equal(result, df)

py-polars/tests/unit/datatypes/test_enum.py

+25
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,31 @@ def test_nested_enum_concat() -> None:
180180
assert_series_equal(s1.extend(s2), expected)
181181

182182

183+
def test_nested_enum_agg_sort_18026() -> None:
184+
df = (
185+
pl.DataFrame({"a": [1, 1, 2, 2], "b": ["Y", "Z", "Z", "Y"]})
186+
.cast({"b": pl.Enum(["Z", "Y"])})
187+
.with_columns(pl.struct("b", "a").alias("c"))
188+
)
189+
result = df.group_by("a").agg("c").sort("a")
190+
expected = pl.DataFrame(
191+
{
192+
"a": [1, 2],
193+
"c": [
194+
[{"b": "Y", "a": 1}, {"b": "Z", "a": 1}],
195+
[{"b": "Z", "a": 2}, {"b": "Y", "a": 2}],
196+
],
197+
},
198+
schema={
199+
"a": pl.Int64,
200+
"c": pl.List(
201+
pl.Struct([pl.Field("b", pl.Enum(["Z", "Y"])), pl.Field("a", pl.Int64)])
202+
),
203+
},
204+
)
205+
assert_frame_equal(result, expected)
206+
207+
183208
def test_casting_to_an_enum_from_utf() -> None:
184209
dtype = pl.Enum(["a", "b", "c"])
185210
s = pl.Series([None, "a", "b", "c"])

py-polars/tests/unit/io/test_csv.py

+7
Original file line numberDiff line numberDiff line change
@@ -2501,3 +2501,10 @@ def test_trailing_separator_8240() -> None:
25012501

25022502
result = pl.scan_csv(io.StringIO(csv), separator="|", has_header=False).collect()
25032503
assert_frame_equal(result, expected)
2504+
2505+
2506+
def test_header_only_column_selection_17173() -> None:
2507+
csv = "A,B"
2508+
result = pl.read_csv(io.StringIO(csv), columns=["B"])
2509+
expected = pl.Series("B", [], pl.String()).to_frame()
2510+
assert_frame_equal(result, expected)

py-polars/tests/unit/operations/test_fill_null.py

+7
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ def test_fill_null_lit_() -> None:
6161
df.fill_null(pl.lit(0)).select(pl.all().null_count()).transpose().sum().item()
6262
== 0
6363
)
64+
65+
66+
def test_fill_null_decimal_with_int_14331() -> None:
67+
s = pl.Series("a", ["1.1", None], dtype=pl.Decimal(precision=None, scale=5))
68+
result = s.fill_null(0)
69+
expected = pl.Series("a", ["1.1", "0.0"], dtype=pl.Decimal(precision=None, scale=5))
70+
assert_series_equal(result, expected)

py-polars/tests/unit/series/test_item.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import datetime
4+
35
import pytest
46

57
import polars as pl
@@ -36,3 +38,9 @@ def test_series_item_with_index(index: int, expected: int, s: pl.Series) -> None
3638
def test_df_item_out_of_bounds(index: int, s: pl.Series) -> None:
3739
with pytest.raises(IndexError, match="out of bounds"):
3840
s.item(index)
41+
42+
43+
def test_series_item_out_of_range_date() -> None:
44+
s = pl.Series([datetime.date(9999, 12, 31)]).dt.offset_by("1d")
45+
with pytest.raises(ValueError, match="out of range"):
46+
s.item()

0 commit comments

Comments
 (0)