Skip to content

Commit 378f7c1

Browse files
author
gabriel
committed
fix: Ignore columns in
1 parent 72fb1a6 commit 378f7c1

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

dataframely/schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
ParquetStorageBackend,
3939
)
4040
from ._typing import DataFrame, LazyFrame, Validation
41+
from .columns import Any as AnyColumn
4142
from .columns import Column, column_from_dict
4243
from .config import Config
4344
from .exc import (
@@ -814,7 +815,9 @@ def cast(
814815
further down the line might fail because of the cast and/or missing columns.
815816
"""
816817
lf = df.lazy().select(
817-
pl.col(name).cast(col.dtype) for name, col in cls.columns().items()
818+
# Skip casting for Any columns since they accept any type
819+
pl.col(name) if isinstance(col, AnyColumn) else pl.col(name).cast(col.dtype)
820+
for name, col in cls.columns().items()
818821
)
819822
if isinstance(df, pl.DataFrame):
820823
return lf.collect() # type: ignore

tests/column_types/test_any.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ class AnySchema(dy.Schema):
2020
def test_any_dtype_passes(data: dict[str, Any]) -> None:
2121
df = pl.DataFrame(data)
2222
assert AnySchema.is_valid(df)
23+
24+
25+
def test_any_cast() -> None:
26+
df = pl.DataFrame({"a": 0})
27+
result = AnySchema.cast(df)
28+
assert result["a"].dtype == pl.Int64

0 commit comments

Comments
 (0)