Skip to content

Commit b5494bc

Browse files
authored
test: Add tests for already resolved issues (#20921)
1 parent 14c673e commit b5494bc

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,22 @@ def test_unique() -> None:
659659
assert ser.unique().to_list() == [D("1.1"), D("2.2")]
660660
assert ser.n_unique() == 2
661661
assert ser.arg_unique().to_list() == [0, 2]
662+
663+
664+
def test_groupby_agg_single_element_11232() -> None:
665+
data = {"g": [-1], "decimal": [-1]}
666+
schema = {"g": pl.Int64(), "decimal": pl.Decimal(38, 0)}
667+
result = (
668+
pl.LazyFrame(data, schema=schema)
669+
.group_by("g", maintain_order=True)
670+
.agg(pl.col("decimal").min())
671+
.collect()
672+
)
673+
expected = pl.DataFrame(data, schema=schema)
674+
assert_frame_equal(result, expected)
675+
676+
677+
def test_decimal_from_large_ints_9084() -> None:
678+
numbers = [2963091539321097135000000000, 25658709114149718824803874]
679+
s = pl.Series(numbers, dtype=pl.Decimal)
680+
assert s.to_list() == [D(n) for n in numbers]

py-polars/tests/unit/functions/as_datatype/test_concat_list.py

+20
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,23 @@ def test_concat_list_empty() -> None:
172172
def test_concat_list_empty_struct() -> None:
173173
df = pl.DataFrame({"a": []}, schema={"a": pl.Struct({"b": pl.Boolean})})
174174
df.select(pl.concat_list("a"))
175+
176+
177+
def test_cross_join_concat_list_18587() -> None:
178+
lf = pl.LazyFrame({"u32": [0, 1], "str": ["a", "b"]})
179+
180+
lf1 = lf.select(pl.struct(pl.all()).alias("1"))
181+
lf2 = lf.select(pl.struct(pl.all()).alias("2"))
182+
lf3 = lf.select(pl.struct(pl.all()).alias("3"))
183+
184+
result = (
185+
lf1.join(lf2, how="cross")
186+
.join(lf3, how="cross")
187+
.select(pl.concat_list("1", "2", "3"))
188+
.collect()
189+
)
190+
191+
vals = [{"u32": 0, "str": "a"}, {"u32": 1, "str": "b"}]
192+
expected = [[a, b, c] for a in vals for b in vals for c in vals]
193+
194+
assert result["1"].to_list() == expected

py-polars/tests/unit/functions/test_when_then.py

+18
Original file line numberDiff line numberDiff line change
@@ -736,3 +736,21 @@ def test_struct_when_then_broadcasting_combinations_19122(
736736
pl.when(pl.col.a.struct.field("x") != 0).then(rv).otherwise(None).alias("a")
737737
),
738738
)
739+
740+
741+
def test_when_then_to_decimal_18375() -> None:
742+
df = pl.DataFrame({"a": ["1.23", "4.56"]})
743+
744+
result = df.with_columns(
745+
b=pl.when(False).then(None).otherwise(pl.col("a").str.to_decimal()),
746+
c=pl.when(True).then(pl.col("a").str.to_decimal()),
747+
)
748+
expected = pl.DataFrame(
749+
{
750+
"a": ["1.23", "4.56"],
751+
"b": ["1.23", "4.56"],
752+
"c": ["1.23", "4.56"],
753+
},
754+
schema={"a": pl.String, "b": pl.Decimal, "c": pl.Decimal},
755+
)
756+
assert_frame_equal(result, expected)

py-polars/tests/unit/operations/namespaces/list/test_list.py

+6
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,12 @@ def test_list_to_struct() -> None:
680680
).collect_schema() == {"n": pl.Unknown}
681681

682682

683+
def test_list_to_struct_all_null_12119() -> None:
684+
s = pl.Series([None], dtype=pl.List(pl.Int64))
685+
result = s.list.to_struct(fields=["a", "b", "c"]).to_list()
686+
assert result == [{"a": None, "b": None, "c": None}]
687+
688+
683689
def test_select_from_list_to_struct_11143() -> None:
684690
ldf = pl.LazyFrame({"some_col": [[1.0, 2.0], [1.5, 3.0]]})
685691
ldf = ldf.select(

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

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import datetime
2+
3+
import pytest
4+
15
import polars as pl
26
from polars.testing import assert_series_equal
37

@@ -68,3 +72,15 @@ def test_fill_null_decimal_with_int_14331() -> None:
6872
result = s.fill_null(0)
6973
expected = pl.Series("a", ["1.1", "0.0"], dtype=pl.Decimal(precision=None, scale=5))
7074
assert_series_equal(result, expected)
75+
76+
77+
def test_fill_null_date_with_int_11362() -> None:
78+
match = "got invalid or ambiguous dtypes"
79+
80+
s = pl.Series([datetime.date(2000, 1, 1)])
81+
with pytest.raises(pl.exceptions.InvalidOperationError, match=match):
82+
s.fill_null(0)
83+
84+
s = pl.Series([None], dtype=pl.Date)
85+
with pytest.raises(pl.exceptions.InvalidOperationError, match=match):
86+
s.fill_null(1)

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

+6
Original file line numberDiff line numberDiff line change
@@ -1278,3 +1278,9 @@ def test_join_asof_no_exact_matches() -> None:
12781278
"bid": [None, 51.97, None, None, None],
12791279
"ask": [None, 51.98, None, None, None],
12801280
}
1281+
1282+
1283+
def test_join_asof_not_sorted_warning() -> None:
1284+
df = pl.DataFrame({"a": [1, 1, 1, 2, 2, 2], "b": [2, 1, 3, 1, 2, 3]})
1285+
with pytest.warns(UserWarning, match="asof join is not sorted"):
1286+
df.join_asof(df, on="b", by="a")

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

+6
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,9 @@ def assert_series_equal(
297297
),
298298
pl.Series([False, True, False]),
299299
)
300+
301+
302+
def test_equals_nested_null_categorical_14875() -> None:
303+
dtype = pl.List(pl.Struct({"cat": pl.Categorical}))
304+
s = pl.Series([[{"cat": None}]], dtype=dtype)
305+
assert s.equals(s)

0 commit comments

Comments
 (0)