Skip to content

Conversation

@cofin
Copy link
Member

@cofin cofin commented Nov 26, 2025

Summary

Add to_arrow(), to_pandas(), and to_polars() methods to the SQLResult class for consistent API with ArrowResult. Enables convenient conversion of dict-based query results to popular data science formats.

The Problem

ArrowResult has convenient DataFrame conversion methods, but SQLResult (which stores results as list[dict[str, Any]]) lacks these methods. Users must manually convert results when they want to work with pandas or Polars DataFrames.

The Solution

Add three conversion methods to SQLResult that mirror the ArrowResult API:

  • to_arrow() - Converts to Arrow Table using existing convert_dict_to_arrow() helper
  • to_pandas() - Direct conversion via pd.DataFrame()
  • to_polars() - Direct conversion via pl.DataFrame()

Key Features

  • API consistency: Same method names and behavior as ArrowResult
  • Lazy imports: Libraries loaded only when methods are called
  • Proper error handling: ValueError when data is None, empty data returns empty DataFrame/Table
  • NULL preservation: Correctly handles null values in data
  • Comprehensive tests: 10 unit tests covering all methods and edge cases

@cofin cofin merged commit ee4ea74 into main Nov 26, 2025
11 checks passed
@cofin cofin deleted the feat/to-arrow-sqlresult branch November 26, 2025 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants