cycquery.ops.Cast

class Cast(cols, type_)[source]

Bases: QueryOp

Cast columns to a specified type.

Currently supporting conversions to str, int, float, date, bool and timestamp.

Parameters:
  • cols (Union[str, List[str]]) – Columns to cast.

  • type – Name of type to which to convert. Must be supported.

Examples

>>> Cast("col1", "str")(table)
>>> Cast(["col1", "col2"], "int")(table)
>>> Cast("col1", "float")(table)
>>> Cast("col1", "date")(table)
>>> Cast("col1", "bool")(table)
>>> Cast("col1", "timestamp")(table)

Initialize the operation.

Methods

__call__(table)[source]

Process the table.

Parameters:

table (Union[Select, Subquery, Table, DBTable]) – Table on which to perform the operation.

Returns:

Processed table.

Return type:

sqlalchemy.sql.selectable.Subquery

__init__(cols, type_)[source]

Initialize the operation.