Path: blob/main/py-polars/tests/unit/lazyframe/test_collect_schema.py
8446 views
import pytest1from hypothesis import given23import polars as pl4from polars.testing.parametric import dataframes567@given(lf=dataframes(lazy=True))8def test_collect_schema_parametric(lf: pl.LazyFrame) -> None:9assert lf.collect_schema() == lf.collect().schema101112def test_collect_schema() -> None:13lf = pl.LazyFrame(14{15"foo": [1, 2, 3],16"bar": [6.0, 7.0, 8.0],17"ham": ["a", "b", "c"],18}19)20result = lf.collect_schema()21expected = pl.Schema({"foo": pl.Int64(), "bar": pl.Float64(), "ham": pl.String()})22assert result == expected232425def test_collect_schema_with_row_index_duplicate() -> None:26lf = pl.LazyFrame({"index": []}).with_row_index()27with pytest.raises(28pl.exceptions.DuplicateError, match="duplicate column name index"29):30_ = lf.collect_schema()3132lf = pl.LazyFrame({}).with_row_index().with_row_index()33with pytest.raises(34pl.exceptions.DuplicateError, match="duplicate column name index"35):36_ = lf.collect_schema()373839def test_collect_schema_unpivot_duplicate() -> None:40lf = pl.LazyFrame({"variable": [], "a": []}).unpivot(["a"])41with pytest.raises(42pl.exceptions.DuplicateError, match="duplicate column name 'variable'"43):44_ = lf.collect_schema()4546lf = pl.LazyFrame({"value": [], "a": []}).unpivot(["a"])47with pytest.raises(48pl.exceptions.DuplicateError, match="duplicate column name 'value'"49):50_ = lf.collect_schema()515253