Skip to content

Commit

Permalink
test: Add tests for various open issues (#20720)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemanley authored Jan 15, 2025
1 parent ab8060f commit f3906ec
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
25 changes: 25 additions & 0 deletions py-polars/tests/unit/constructors/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,31 @@ def test_from_dicts_schema_columns_do_not_match() -> None:
assert_frame_equal(result, expected)


def test_from_dicts_infer_integer_types() -> None:
data = [
{
"a": 2**7 - 1,
"b": 2**15 - 1,
"c": 2**31 - 1,
"d": 2**63 - 1,
"e": 2**127 - 1,
}
]
result = pl.from_dicts(data).schema
# all values inferred as i64 except for values too large for i64
expected = {
"a": pl.Int64,
"b": pl.Int64,
"c": pl.Int64,
"d": pl.Int64,
"e": pl.Int128,
}
assert result == expected

with pytest.raises(OverflowError):
pl.from_dicts([{"too_big": 2**127}])


def test_from_rows_dtype() -> None:
# 50 is the default inference length
# 5182
Expand Down
15 changes: 15 additions & 0 deletions py-polars/tests/unit/datatypes/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,18 @@ def test_decimal_horizontal_20482() -> None:
"max": [D("123.000000"), D("234.000000")],
"sum": [D("246.000000"), D("468.000000")],
}


def test_shift_over_12957() -> None:
df = pl.DataFrame(
{
"a": [1, 1, 2, 2],
"b": [D("1.1"), D("1.1"), D("2.2"), D("2.2")],
}
)
result = df.select(
x=pl.col("b").shift(1).over("a"),
y=pl.col("a").shift(1).over("b"),
)
assert result["x"].to_list() == [None, D("1.1"), None, D("2.2")]
assert result["y"].to_list() == [None, 1, None, 2]
9 changes: 9 additions & 0 deletions py-polars/tests/unit/io/test_lazy_csv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import io
import tempfile
from collections import OrderedDict
from pathlib import Path
Expand Down Expand Up @@ -438,3 +439,11 @@ def test_scan_csv_with_column_names_nonexistent_file() -> None:
# Upon collection, it should fail
with pytest.raises(FileNotFoundError):
result.collect()


def test_select_nonexistent_column() -> None:
csv = "a\n1"
f = io.StringIO(csv)

with pytest.raises(pl.exceptions.ColumnNotFoundError):
pl.scan_csv(f).select("b").collect()
13 changes: 13 additions & 0 deletions py-polars/tests/unit/streaming/test_streaming_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,16 @@ def test_flush_join_and_operation_19040() -> None:
"B": [None, 1],
"C": [None, 1],
}


def test_full_coalesce_join_and_rename_15583() -> None:
df1 = pl.LazyFrame({"a": [1, 2, 3]})
df2 = pl.LazyFrame({"a": [3, 4, 5]})

result = (
df1.join(df2, on="a", how="full", coalesce=True)
.select(pl.all().name.map(lambda c: c.upper()))
.sort("A")
.collect(streaming=True)
)
assert result["A"].to_list() == [1, 2, 3, 4, 5]
7 changes: 7 additions & 0 deletions py-polars/tests/unit/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,10 @@ def test_empty_input_expansion() -> None:
pl.col("B").sort_by(pl.struct(pl.exclude("A", "B")))
)
)


def test_empty_list_15523() -> None:
s = pl.Series("", [["a"], []], dtype=pl.List)
assert s.dtype == pl.List(pl.String)
s = pl.Series("", [[], ["a"]], dtype=pl.List)
assert s.dtype == pl.List(pl.String)

0 comments on commit f3906ec

Please sign in to comment.