bach.DataFrame.from_model

classmethod from_model​

(engine, model, index, all_dtypes=None, name_to_column_mapping=None)

​[source]

Instantiate a new DataFrame based on the result of the query defined in model.

If all_dtypes is not specified, then the model is compiled to sql and executed as a query on the database. The result-set’s meta data is used to determine the columns and dtypes. This might not work with custom data types. If the all_dtypes data is available, it’s advised to provide it.

Parameters​

  • engine (sqlalchemy.engine.base.Engine) – a sqlalchemy engine for the database.
  • model (sql_models.model.SqlModel) – an SqlModel that specifies the queries to instantiate as DataFrame.
  • index (List[str]) – list of series names that make up the index. At least one series needs to be selected for the index.
  • all_dtypes (Optional[Mapping[str, Union[List[Any], Mapping[str, Any], str]]]) – Optional. Mapping series name to dtype. Must contain all index and data series. Must be in same order as the columns appear in the sql-model.
  • name_to_column_mapping (Optional[Mapping[str, str]]) – Optional mapping from series names to the actual column names in the model result. If mapping is None or missing a specific name, then the column name is assumed to be the same as the series name.

Returns​

A DataFrame based on an SqlModel

Return type​

bach.dataframe.DataFrame

note

If all_dtypes is not set, then this will query the database