[Python] Cursor.fetch_polars() returns a struct Series instead of a DataFrame with polars 2
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
_RowIterator.fetch_polars() in the Python driver manager is the entry point: it wraps polars.from_arrow(self.fetch_arrow()) in a typing.cast, which hides that polars 2 returns a polars.Series. Start by running the sqlite repro in the report and confirming the Series/struct output, then apply the unnest (or build a polars.DataFrame from the stream) and check the result is a DataFrame with columns a and b under both polars 1.x and 2.x, including an empty result.
Written by the indexing model from the issue text.
Description
Describe the bug
With polars 2.0, adbc_driver_manager.dbapi.Cursor.fetch_polars() returns a polars.Series with a single struct column instead of a polars.DataFrame.
_RowIterator.fetch_polars() calls polars.from_arrow(self.fetch_arrow()), which passes in an ArrowArrayStreamHandle. polars 2 now turns an Arrow C stream given to from_arrow into a struct Series. polars 1.x returned a DataFrame. The typing.cast(polars.DataFrame, ...) around the call hides this from type checkers.
Reproduce
import adbc_driver_sqlite.dbapi as d
with d.connect() as c, c.cursor() as cur:
cur.execute("SELECT 1 AS a, 'x' AS b")
r = cur.fetch_polars()
print(type(r).__name__, r.dtype, r.shape)
Output with polars 2.0.0:
Series Struct({'a': Int64, 'b': String}) (1,)
Expected: a DataFrame with columns a and b. That is what polars 1.x returns.
Versions
- adbc-driver-manager 1.12.0
- polars 2.0.0
- pyarrow 26.0.0
- Python 3.12, Linux
Possible fix
One option is to unnest when polars hands back a Series:
result = polars.from_arrow(self.fetch_arrow())
if isinstance(result, polars.Series):
result = result.struct.unnest()
Another is to build the frame with polars.DataFrame(...) from the stream. That needs checking against both polars 1.x and 2.x. We've applied the unnest workaround downstream in adbc-poolhouse 1.6.4, and it keeps the frame's schema, including for empty results.
- Dominant language
- C#
- Stars
- 634
- Forks
- 233
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 91
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/arrow-adbc
-
go: some option constants are named wronglyMay be free again @aryan9948 claimed this 12 days ago, and no pull request is open. OpenType: enhancement
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/arrow-adbc#4818 · 4 comments ·
Maintainers usually reply within 1 day
-
Type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
apache/arrow-adbc#4809 · 3 comments ·
Maintainers usually reply within 1 day
-
Type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/arrow-adbc#4753 ·
Maintainers usually reply within 1 day
-
Type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/arrow-adbc#4375 ·
Maintainers usually reply within 1 day
-
Type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/arrow-adbc#4153 ·
Maintainers usually reply within 1 day
All issues in apache/arrow-adbc
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
dette technique priorité: basse zone: service
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
damiensabau/nexus-lobby#25 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sebastienros/jint#4282 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
pyrevitlabs/pyRevit#3792 ·
Maintainers usually reply within 1 day