Skip to content
Merged
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
103 changes: 93 additions & 10 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import date, datetime, time
from functools import partial
import re
from typing import Iterator, Optional, Union, overload
import warnings

import numpy as np
Expand Down Expand Up @@ -162,6 +163,7 @@ def execute(sql, con, cur=None, params=None):
# -- Read and write to DataFrames


@overload
def read_sql_table(
table_name,
con,
Expand All @@ -170,8 +172,35 @@ def read_sql_table(
coerce_float=True,
parse_dates=None,
columns=None,
chunksize=None,
):
chunksize: None = None,
) -> DataFrame:
...


@overload
def read_sql_table(
table_name,
con,
schema=None,
index_col=None,
coerce_float=True,
parse_dates=None,
columns=None,
chunksize: int = 1,
) -> Iterator[DataFrame]:
...


def read_sql_table(
table_name,
con,
schema=None,
index_col=None,
coerce_float=True,
parse_dates=None,
columns=None,
chunksize: Optional[int] = None,
) -> Union[DataFrame, Iterator[DataFrame]]:
"""
Read SQL database table into a DataFrame.

Expand Down Expand Up @@ -210,7 +239,7 @@ def read_sql_table(

Returns
-------
DataFrame
DataFrame or Iterator[DataFrame]
A SQL table is returned as two-dimensional data structure with labeled
axes.

Expand Down Expand Up @@ -257,15 +286,41 @@ def read_sql_table(
raise ValueError(f"Table {table_name} not found", con)


@overload
def read_sql_query(
sql,
con,
index_col=None,
coerce_float=True,
params=None,
parse_dates=None,
chunksize=None,
):
chunksize: None = None,
) -> DataFrame:
...


@overload
def read_sql_query(
sql,
con,
index_col=None,
coerce_float=True,
params=None,
parse_dates=None,
chunksize: int = 1,
) -> Iterator[DataFrame]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the return types of the two overloads switched? or have a misread the docstring?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea looks like a copy / paste error? The other two funcs look correct.

lgtm outside of this issue

...


def read_sql_query(
sql,
con,
index_col=None,
coerce_float=True,
params=None,
parse_dates=None,
chunksize: Optional[int] = None,
) -> Union[DataFrame, Iterator[DataFrame]]:
"""
Read SQL query into a DataFrame.

Expand Down Expand Up @@ -308,7 +363,7 @@ def read_sql_query(

Returns
-------
DataFrame
DataFrame or Iterator[DataFrame]

See Also
--------
Expand All @@ -331,6 +386,7 @@ def read_sql_query(
)


@overload
def read_sql(
sql,
con,
Expand All @@ -339,8 +395,35 @@ def read_sql(
params=None,
parse_dates=None,
columns=None,
chunksize=None,
):
chunksize: None = None,
) -> DataFrame:
...


@overload
def read_sql(
sql,
con,
index_col=None,
coerce_float=True,
params=None,
parse_dates=None,
columns=None,
chunksize: int = 1,
) -> Iterator[DataFrame]:
...


def read_sql(
sql,
con,
index_col=None,
coerce_float=True,
params=None,
parse_dates=None,
columns=None,
chunksize: Optional[int] = None,
) -> Union[DataFrame, Iterator[DataFrame]]:
"""
Read SQL query or database table into a DataFrame.

Expand Down Expand Up @@ -391,7 +474,7 @@ def read_sql(

Returns
-------
DataFrame
DataFrame or Iterator[DataFrame]

See Also
--------
Expand Down Expand Up @@ -448,7 +531,7 @@ def to_sql(
chunksize=None,
dtype=None,
method=None,
):
) -> None:
"""
Write records stored in a DataFrame to a SQL database.

Expand Down