Skip to content

Querytopandas

flowtask.components.QueryToPandas

QueryToPandas

QueryToPandas(loop=None, job=None, stat=None, **kwargs)

Bases: TemplateSupport, FlowComponent, QSSupport

QueryToPandas.

Overview

This component fetches data using QuerySource and transforms it into a Pandas DataFrame.

.. table:: Properties :widths: auto

+--------------+----------+-----------+-------------------------------------------------------+ | Name | Required | Summary | +--------------+----------+-----------+-------------------------------------------------------+ | query | Yes | Represents an SQL query | +--------------+----------+-----------+-------------------------------------------------------+ | query_slug | Yes | Named queries that are saved in Navigator (QuerySource) | +--------------+----------+-----------+-------------------------------------------------------+ | as_dict | Yes | True | False. if true, it returns the data in JSON format | | | | instead of a dataframe | +--------------+----------+-----------+-------------------------------------------------------+ | raw_result | Yes | Returns the data in the NATIVE FORMAT of the database for | | | | example ( pg RECORDSET) | +--------------+----------+-----------+-------------------------------------------------------+ | file_sql | Yes | SQL comes from a sql file | +--------------+----------+-----------+-------------------------------------------------------+ | use_template | Yes | The component is passed to the SQL file through a template | | | | replacement system | +--------------+----------+-----------+-------------------------------------------------------+ | infer_types | Yes | Type inference, give the component the power to decide the data | | | | types of each column | +--------------+----------+-----------+-------------------------------------------------------+ | drop_empty | Yes | False | True delete (drop) any column that is empty | +--------------+----------+-----------+-------------------------------------------------------+ | dropna | Yes | False | True delete all NA (Not a Number) | +--------------+----------+-----------+-------------------------------------------------------+ | fillna | Yes | False | True fills with an EMPTY SPACE all the NAs of the | | | | dataframe | +--------------+----------+-----------+-------------------------------------------------------+ | clean_strings| Yes | Fills with an empty space the NA,but ONLY of the fields of | | | | type string | +--------------+----------+-----------+-------------------------------------------------------+ | clean_dates | Yes | Declares NONE any date field that has a NAT (Not a Time) | +--------------+----------+-----------+-------------------------------------------------------+ | conditions | Yes | This attribute allows me to apply conditions to filter the data | +--------------+----------+-----------+-------------------------------------------------------+ | formit | Yes | Form id (i have doubts about this) | +--------------+----------+-----------+-------------------------------------------------------+ | orgid | Yes | Organization id (i have doubts about this) | +--------------+----------+-----------+-------------------------------------------------------+ | refresh | Yes | Refreshes the data in the QueryToPandas | +--------------+----------+-----------+-------------------------------------------------------+ | to_string | No | Whether to convert all data to string type. Default is True. | +--------------+----------+-----------+-------------------------------------------------------+ | as_objects | No | Whether to return the result as objects. Default is True. | +--------------+----------+-----------+-------------------------------------------------------+ | datatypes | No | A dictionary specifying data types for columns. | +--------------+----------+-----------+-------------------------------------------------------+ | datasource | No | The datasource to fetch the data from. Default is "db". | +--------------+----------+-----------+-------------------------------------------------------+ Returns

This component returns a Pandas DataFrame if the query is successfully executed and data is fetched, otherwise raises a ComponentError.

Example:

```yaml
QueryToPandas:
  query: SELECT formid, orgid FROM banco.forms WHERE enabled = true
```

close async

close()

Method.