cycquery.ops.ExtractTimestampComponent

class ExtractTimestampComponent(timestamp_col, extract_str, label)[source]

Bases: QueryOp

Extract a component such as year or month from a timestamp column.

Parameters:
  • timestamp_col (str) – Timestamp column from which to extract the time component.

  • extract_str (str) – Information to extract, e.g., “year”, “month”

  • label (str) – Column label for the extracted column.

Examples

>>> ExtractTimestampComponent("col1", "year", "year")(table)
>>> ExtractTimestampComponent("col1", "month", "month")(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__(timestamp_col, extract_str, label)[source]

Initialize the operation.