DataFrameBaseView#
Tip
To learn how to use Pandas DataFrame with db-ally see How To: Use Pandas DataFrames with db-ally.
dbally.DataFrameBaseView
#
Bases: MethodsBaseView
Base class for views that use Pandas DataFrames to store and filter data.
The views take a Pandas DataFrame as input and apply filters to it. The filters are defined as methods that return a Pandas Series representing a boolean mask to be applied to the DataFrame.
Creates a new instance of the DataFrame view.
PARAMETER | DESCRIPTION |
---|---|
df |
Pandas DataFrame with the data to be filtered.
TYPE:
|
Source code in src/dbally/views/pandas_base.py
ask
async
#
ask(query: str, llm: LLM, event_tracker: Optional[EventTracker] = None, n_retries: int = 3, dry_run: bool = False, llm_options: Optional[LLMOptions] = None) -> ViewExecutionResult
Executes the query and returns the result. It generates the IQL query from the natural language query and applies the filters to the view. It retries the process in case of errors.
PARAMETER | DESCRIPTION |
---|---|
query |
The natural language query to execute.
TYPE:
|
llm |
The LLM used to execute the query.
TYPE:
|
event_tracker |
The event tracker used to audit the query execution.
TYPE:
|
n_retries |
The number of retries to execute the query in case of errors.
TYPE:
|
dry_run |
If True, the query will not be used to fetch data from the datasource.
TYPE:
|
llm_options |
Options to use for the LLM.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ViewExecutionResult
|
The result of the query. |
RAISES | DESCRIPTION |
---|---|
ViewExecutionError
|
When an error occurs while executing the view. |
Source code in src/dbally/views/structured.py
list_similarity_indexes
#
Lists all the similarity indexes used by the view.
RETURNS | DESCRIPTION |
---|---|
Dict[AbstractSimilarityIndex, List[IndexLocation]]
|
Mapping of similarity indexes to their locations in the (view_name, filter_name, argument_name) format. |
Source code in src/dbally/views/structured.py
list_few_shots
#
list_few_shots() -> List[FewShotExample]
List all examples to be injected into few-shot prompt.
RETURNS | DESCRIPTION |
---|---|
List[FewShotExample]
|
List of few-shot examples |
get_iql_generator
#
get_iql_generator() -> IQLGenerator
Returns the IQL generator for the view.
RETURNS | DESCRIPTION |
---|---|
IQLGenerator
|
IQL generator for the view. |
list_filters
#
list_filters() -> List[ExposedFunction]
List filters in the given view
RETURNS | DESCRIPTION |
---|---|
List[ExposedFunction]
|
Filters defined inside the View and decorated with |
Source code in src/dbally/views/methods_base.py
list_aggregations
#
list_aggregations() -> List[ExposedFunction]
List aggregations in the given view
RETURNS | DESCRIPTION |
---|---|
List[ExposedFunction]
|
Aggregations defined inside the View and decorated with |
Source code in src/dbally/views/methods_base.py
list_methods_by_decorator
classmethod
#
list_methods_by_decorator(decorator: Callable) -> List[ExposedFunction]
Lists all methods decorated with the given decorator.
PARAMETER | DESCRIPTION |
---|---|
decorator |
The decorator to filter the methods
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[ExposedFunction]
|
List of exposed methods |
Source code in src/dbally/views/methods_base.py
call_filter_method
async
#
call_filter_method(func: FunctionCall) -> Any
Converts a IQL FunctonCall filter to a method call. If the method is a coroutine, it will be awaited.
PARAMETER | DESCRIPTION |
---|---|
func |
IQL FunctionCall node
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The result of the method call |
Source code in src/dbally/views/methods_base.py
call_aggregation_method
async
#
call_aggregation_method(func: FunctionCall) -> Any
Converts a IQL FunctonCall aggregation to a method call. If the method is a coroutine, it will be awaited.
PARAMETER | DESCRIPTION |
---|---|
func |
IQL FunctionCall node
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The result of the method call |
Source code in src/dbally/views/methods_base.py
apply_filters
async
#
Applies the chosen filters to the view.
PARAMETER | DESCRIPTION |
---|---|
filters |
IQLQuery object representing the filters to apply.
TYPE:
|
Source code in src/dbally/views/pandas_base.py
apply_aggregation
async
#
Applies the aggregation of choice to the view.
PARAMETER | DESCRIPTION |
---|---|
aggregation |
IQLQuery object representing the aggregation to apply.
TYPE:
|
Source code in src/dbally/views/pandas_base.py
execute
#
execute(dry_run: bool = False) -> ViewExecutionResult
Executes the view and returns the results. The results are filtered based on the applied filters.
PARAMETER | DESCRIPTION |
---|---|
dry_run |
If True, the method will only add
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ViewExecutionResult
|
ExecutionResult object with the results and the context information with the binary mask. |