Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): Add missing read_database overload #16229

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion py-polars/polars/io/database/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def read_database(
query: str | Selectable,
connection: ConnectionOrCursor | str,
*,
iter_batches: Literal[False] = False,
iter_batches: Literal[False] = ...,
batch_size: int | None = ...,
schema_overrides: SchemaDict | None = ...,
infer_schema_length: int | None = ...,
Expand All @@ -55,6 +55,20 @@ def read_database(
) -> Iterable[DataFrame]: ...


@overload
def read_database(
query: str | Selectable,
connection: ConnectionOrCursor | str,
*,
iter_batches: bool,
batch_size: int | None = ...,
schema_overrides: SchemaDict | None = ...,
infer_schema_length: int | None = ...,
execute_options: dict[str, Any] | None = ...,
**kwargs: Any,
) -> DataFrame | Iterable[DataFrame]: ...


def read_database( # noqa: D417
query: str | Selectable,
connection: ConnectionOrCursor | str,
Expand Down
5 changes: 3 additions & 2 deletions py-polars/tests/unit/io/database/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from datetime import date
from pathlib import Path
from types import GeneratorType
from typing import TYPE_CHECKING, Any, NamedTuple
from typing import TYPE_CHECKING, Any, NamedTuple, cast

import pyarrow as pa
import pytest
Expand Down Expand Up @@ -469,7 +469,7 @@ def test_read_database_mocked(
"repeat_batch_calls", False
),
)
res = pl.read_database( # type: ignore[call-overload]
stinodego marked this conversation as resolved.
Show resolved Hide resolved
res = pl.read_database(
query="SELECT * FROM test_data",
connection=mc,
iter_batches=iter_batches,
Expand All @@ -479,6 +479,7 @@ def test_read_database_mocked(
assert isinstance(res, GeneratorType)
res = pl.concat(res)

res = cast(pl.DataFrame, res)
stinodego marked this conversation as resolved.
Show resolved Hide resolved
assert expected_call in mc.cursor().called
assert res.rows() == [(1, "aa"), (2, "bb"), (3, "cc")]

Expand Down