MCPcopy
hub / github.com/pathwaycom/pathway / cast

Function cast

python/pathway/internals/common.py:242–272  ·  view source on GitHub ↗

Changes the type of the column to target_type and converts the data of this column Example: >>> import pathway as pw >>> t1 = pw.debug.table_from_markdown(''' ... val ... 1 10 ... 2 9 ... 3 8 ... 4 7''') >>> t1.schema <pathway.Schema types={'val

(target_type: Any, col: expr.ColumnExpression | Value)

Source from the content-addressed store, hash-verified

240
241
242def cast(target_type: Any, col: expr.ColumnExpression | Value) -> expr.CastExpression:
243 """Changes the type of the column to target_type and converts the data of this column
244
245 Example:
246
247 >>> import pathway as pw
248 >>> t1 = pw.debug.table_from_markdown(''&#x27;
249 ... val
250 ... 1 10
251 ... 2 9
252 ... 3 8
253 ... 4 7''&#x27;)
254 >>> t1.schema
255 <pathway.Schema types={'val': <class 'int'>}, id_type=<class 'pathway.engine.Pointer'>>
256 >>> pw.debug.compute_and_print(t1, include_id=False)
257 val
258 7
259 8
260 9
261 10
262 >>> t2 = t1.select(val = pw.cast(float, t1.val))
263 >>> t2.schema
264 <pathway.Schema types={'val': <class 'float'>}, id_type=<class 'pathway.engine.Pointer'>>
265 >>> pw.debug.compute_and_print(t2, include_id=False)
266 val
267 7.0
268 8.0
269 9.0
270 10.0
271 """
272 return expr.CastExpression(target_type, col)
273
274
275@check_arg_types

Callers 7

from_columnsMethod · 0.90
cast_to_typesMethod · 0.90
verify_dict_keysFunction · 0.85
_table_joinMethod · 0.85
validate_join_conditionFunction · 0.85
to_column_expressionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected