@@ -25,7 +25,13 @@ def polars_to_vortex(expr: pl.Expr) -> ve.Expr:
2525 "LogicalOr" : operator .or_ ,
2626}
2727
28+
29+ def _unsupported (v , name : str ):
30+ raise ValueError (f"Unsupported Polars expression { name } : { v } " )
31+
32+
2833_LITERAL_TYPES = {
34+ "Boolean" : lambda v : vx .bool_ (nullable = v is None ),
2935 "Int" : lambda v : vx .int_ (64 , nullable = v is None ),
3036 "Int8" : lambda v : vx .int_ (8 , nullable = v is None ),
3137 "Int16" : lambda v : vx .int_ (16 , nullable = v is None ),
@@ -37,7 +43,6 @@ def polars_to_vortex(expr: pl.Expr) -> ve.Expr:
3743 "UInt64" : lambda v : vx .uint (64 , nullable = v is None ),
3844 "Float32" : lambda v : vx .float_ (32 , nullable = v is None ),
3945 "Float64" : lambda v : vx .float_ (64 , nullable = v is None ),
40- "Boolean" : lambda v : vx .bool_ (nullable = v is None ),
4146 "Null" : lambda v : vx .null (),
4247 "String" : lambda v : vx .utf8 (nullable = v is None ),
4348 "Binary" : lambda v : vx .binary (nullable = v is None ),
@@ -59,11 +64,28 @@ def _polars_to_vortex(expr: dict) -> ve.Expr:
5964 if "Column" in expr :
6065 return ve .column (expr ["Column" ])
6166
67+ # See https://github.com/pola-rs/polars/pull/21849)
68+ if "Scalar" in expr :
69+ dtype = expr ["Scalar" ]["dtype" ] # DType
70+ value = expr ["Scalar" ]["value" ] # AnyValue
71+
72+ if "Null" in value :
73+ value = None
74+ elif "StringOwned" in value :
75+ value = value ["StringOwned" ]
76+ else :
77+ raise ValueError (f"Unsupported Polars scalar value type { value } " )
78+
79+ return ve .literal (_LITERAL_TYPES [dtype ](value ), value )
80+
6281 if "Literal" in expr :
6382 expr = expr ["Literal" ]
6483
6584 literal_type = next (iter (expr .keys ()), None )
6685
86+ if literal_type == "Scalar" :
87+ return _polars_to_vortex (expr )
88+
6789 # Special-case Series
6890 if literal_type == "Series" :
6991 expr = pl .Expr .from_json (json .dumps ({"Literal" : expr }))
@@ -91,6 +113,12 @@ def _polars_to_vortex(expr: dict) -> ve.Expr:
91113 dtype = vx .ext ("vortex.timestamp" , vx .int_ (64 , nullable = value is None ), metadata = metadata )
92114 return ve .literal (dtype , value )
93115
116+ # Unwrap 'Dyn' scalars, whose type hasn't been established yet.
117+ # (post https://github.com/pola-rs/polars/pull/21849)
118+ if literal_type == "Dyn" :
119+ expr = expr ["Dyn" ]
120+ literal_type = next (iter (expr .keys ()), None )
121+
94122 if literal_type not in _LITERAL_TYPES :
95123 raise NotImplementedError (f"Unsupported Polars literal type: { literal_type } " )
96124 value = expr [literal_type ]
@@ -111,6 +139,11 @@ def _polars_to_vortex(expr: dict) -> ve.Expr:
111139
112140 # Vortex doesn't support is-in, so we need to construct a series of ORs?
113141
142+ if "StringExpr" in fn :
143+ fn = fn ["StringExpr" ]
144+ if "Contains" in fn :
145+ raise ValueError ("Unsupported Polars StringExpr.Contains" )
146+
114147 raise NotImplementedError (f"Unsupported Polars function: { fn } " )
115148
116149 raise NotImplementedError (f"Unsupported Polars expression: { expr } " )
0 commit comments