File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3838 ParquetStorageBackend ,
3939)
4040from ._typing import DataFrame , LazyFrame , Validation
41+ from .columns import Any as AnyColumn
4142from .columns import Column , column_from_dict
4243from .config import Config
4344from .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
Original file line number Diff line number Diff line change @@ -20,3 +20,9 @@ class AnySchema(dy.Schema):
2020def 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
You can’t perform that action at this time.
0 commit comments