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β
note
If all_dtypes is not set, then this will query the database