tessl install tessl/pypi-connectorx@0.4.0Load data from databases to dataframes, the fastest way.
Agent Success
Agent success rate when using this tile
86%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.05x
Baseline
Agent success rate without this tile
82%
Build a Python utility that connects to a database and exports query results to multiple dataframe formats based on user requirements.
Your utility should provide a function export_query_results() that:
@generates
def export_query_results(
connection_string: str,
query: str,
output_format: str,
index_col: str | None = None,
batch_size: int | None = None
) -> Any:
"""
Execute a SQL query and export results to the specified format.
Args:
connection_string: Database connection string (e.g., 'sqlite:///data.db')
query: SQL query to execute
output_format: Desired output format ('pandas', 'arrow', 'polars', 'arrow_stream')
index_col: Optional column name to use as index (pandas only)
batch_size: Optional batch size for streaming (arrow_stream only)
Returns:
Query results in the requested format:
- 'pandas': pandas DataFrame
- 'arrow': pyarrow Table
- 'polars': polars DataFrame
- 'arrow_stream': pyarrow RecordBatchReader
Raises:
ValueError: If output_format is not supported
ValueError: If index_col is specified for non-pandas formats
ValueError: If batch_size is specified for non-streaming formats
"""
passGiven a SQLite database with a simple table, exporting with output_format='pandas' returns a pandas DataFrame with correct data and dtypes @test
Given a SQLite database with a table containing integers, exporting with output_format='arrow' returns a pyarrow Table @test
Given a SQLite database with a table, exporting with output_format='polars' returns a polars DataFrame @test
Given a SQLite database with a table, exporting with output_format='pandas' and index_col='id' returns a pandas DataFrame with 'id' as the index @test
Given a SQLite database with a table, exporting with output_format='arrow_stream' and batch_size=5 returns a RecordBatchReader that yields batches of size 5 @test
Attempting to export with an unsupported output_format raises ValueError @test
Attempting to specify index_col with output_format='arrow' raises ValueError @test
Provides high-performance database-to-dataframe data loading with support for multiple output formats.
@satisfied-by