Skip to content

Commit f60035f

Browse files
committed
ENH: Improve and clean sql io functions
1 parent 8a78a32 commit f60035f

File tree

3 files changed

+70
-168
lines changed

3 files changed

+70
-168
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,18 +2144,6 @@ class DataFrame(NDFrame, OpsMixin):
21442144
compression: _str | Literal["infer", "gzip", "bz2", "zip", "xz"] = ...,
21452145
protocol: int = ...,
21462146
) -> None: ...
2147-
def to_sql(
2148-
self,
2149-
name: _str,
2150-
con,
2151-
schema: _str | None = ...,
2152-
if_exists: _str = ...,
2153-
index: _bool = ...,
2154-
index_label: _str | Sequence[_str] | None = ...,
2155-
chunksize: int | None = ...,
2156-
dtype: dict | Scalar | None = ...,
2157-
method: _str | Callable | None = ...,
2158-
) -> None: ...
21592147
@overload
21602148
def to_string(
21612149
self,

pandas-stubs/core/generic.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ from pandas._typing import (
2121
ArrayLike,
2222
Axis,
2323
Dtype,
24+
DtypeArg,
2425
FilePathOrBuffer,
2526
FrameOrSeries,
2627
FrameOrSeriesUnion,
2728
IgnoreRaise,
2829
Level,
29-
Scalar,
3030
SeriesAxisType,
3131
T,
3232
)
@@ -152,13 +152,13 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
152152
def to_sql(
153153
self,
154154
name: _str,
155-
con,
155+
con: str | Any,
156156
schema: _str | None = ...,
157157
if_exists: _str = ...,
158158
index: _bool = ...,
159-
index_label: _str | Sequence[_str] | None = ...,
159+
index_label: Hashable | Sequence[Hashable] | None = ...,
160160
chunksize: int | None = ...,
161-
dtype: dict | Scalar | None = ...,
161+
dtype: DtypeArg | None = ...,
162162
method: _str | Callable | None = ...,
163163
) -> None: ...
164164
def to_pickle(

pandas-stubs/io/sql.pyi

Lines changed: 66 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,68 @@ from __future__ import annotations
22

33
from typing import (
44
Any,
5+
Callable,
6+
Hashable,
7+
Iterator,
58
Mapping,
69
Sequence,
10+
overload,
711
)
812

9-
from pandas.core.base import PandasObject
1013
from pandas.core.frame import DataFrame
1114

15+
from pandas._typing import DtypeArg
16+
1217
class SQLAlchemyRequired(ImportError): ...
1318
class DatabaseError(IOError): ...
1419

15-
def execute(sql, con, cur=..., params=...): ...
20+
@overload
1621
def read_sql_table(
1722
table_name: str,
18-
con,
23+
con: str | Any,
1924
schema: str | None = ...,
2025
index_col: str | Sequence[str] | None = ...,
2126
coerce_float: bool = ...,
2227
parse_dates: Sequence[str] | Mapping[str, str] | None = ...,
2328
columns: Sequence[str] | None = ...,
24-
chunksize: int | None = ...,
29+
chunksize: None = ...,
2530
) -> DataFrame: ...
26-
def read_sql_query(
27-
sql,
28-
con,
31+
@overload
32+
def read_sql_table(
33+
table_name: str,
34+
con: str | Any,
2935
schema: str | None = ...,
3036
index_col: str | Sequence[str] | None = ...,
3137
coerce_float: bool = ...,
38+
parse_dates: Sequence[str] | Mapping[str, str] | None = ...,
39+
columns: Sequence[str] | None = ...,
40+
*,
41+
chunksize: int,
42+
) -> Iterator[DataFrame]: ...
43+
@overload
44+
def read_sql_query(
45+
sql: str | Any,
46+
con: str | Any,
47+
index_col: str | Sequence[str] | None = ...,
48+
coerce_float: bool = ...,
3249
params=...,
3350
parse_dates: Sequence[str] | Mapping[str, str] | None = ...,
34-
chunksize: int | None = ...,
51+
chunksize: None = ...,
52+
dtype: DtypeArg | None = ...,
3553
) -> DataFrame: ...
54+
@overload
55+
def read_sql_query(
56+
sql: str | Any,
57+
con: str | Any,
58+
index_col: str | Sequence[str] | None = ...,
59+
coerce_float: bool = ...,
60+
params=...,
61+
parse_dates: Sequence[str] | Mapping[str, str] | None = ...,
62+
*,
63+
chunksize: int,
64+
dtype: DtypeArg | None = ...,
65+
) -> Iterator[DataFrame]: ...
66+
@overload
3667
def read_sql(
3768
sql: str | Any,
3869
con: str | Any = ...,
@@ -44,151 +75,34 @@ def read_sql(
4475
| Mapping[str, Mapping[str, Any]]
4576
| None = ...,
4677
columns: Sequence[str] = ...,
47-
chunksize: int = ...,
78+
chunksize: None = ...,
4879
) -> DataFrame: ...
80+
@overload
81+
def read_sql(
82+
sql: str | Any,
83+
con: str | Any = ...,
84+
index_col: str | Sequence[str] | None = ...,
85+
coerce_float: bool = ...,
86+
params: Sequence[str] | tuple[str, ...] | Mapping[str, str] | None = ...,
87+
parse_dates: Sequence[str]
88+
| Mapping[str, str]
89+
| Mapping[str, Mapping[str, Any]]
90+
| None = ...,
91+
columns: Sequence[str] = ...,
92+
*,
93+
chunksize: int,
94+
) -> Iterator[DataFrame]: ...
4995
def to_sql(
50-
frame,
51-
name,
52-
con,
53-
schema=...,
96+
frame: DataFrame,
97+
name: str,
98+
con: Any,
99+
schema: str | None = ...,
54100
if_exists: str = ...,
55101
index: bool = ...,
56-
index_label=...,
57-
chunksize=...,
58-
dtype=...,
59-
method=...,
60-
) -> None: ...
61-
def has_table(table_name, con, schema=...): ...
62-
63-
table_exists = has_table
64-
65-
def pandasSQL_builder(con, schema=..., meta=..., is_cursor: bool = ...): ...
66-
67-
class SQLTable(PandasObject):
68-
name = ...
69-
pd_sql = ...
70-
prefix = ...
71-
frame = ...
72-
index = ...
73-
schema = ...
74-
if_exists = ...
75-
keys = ...
76-
dtype = ...
77-
table = ...
78-
def __init__(
79-
self,
80-
name,
81-
pandas_sql_engine,
82-
frame=...,
83-
index: bool = ...,
84-
if_exists: str = ...,
85-
prefix: str = ...,
86-
index_label=...,
87-
schema=...,
88-
keys=...,
89-
dtype=...,
90-
) -> None: ...
91-
def exists(self): ...
92-
def sql_schema(self): ...
93-
def create(self) -> None: ...
94-
def insert_data(self): ...
95-
def insert(self, chunksize=..., method=...) -> None: ...
96-
def read(
97-
self, coerce_float: bool = ..., parse_dates=..., columns=..., chunksize=...
98-
): ...
99-
100-
class PandasSQL(PandasObject):
101-
def read_sql(self, *args, **kwargs) -> None: ...
102-
def to_sql(
103-
self,
104-
frame,
105-
name,
106-
if_exists: str = ...,
107-
index: bool = ...,
108-
index_label=...,
109-
schema=...,
110-
chunksize=...,
111-
dtype=...,
112-
method=...,
113-
) -> None: ...
114-
115-
class SQLDatabase(PandasSQL):
116-
connectable = ...
117-
meta = ...
118-
def __init__(self, engine, schema=..., meta=...) -> None: ...
119-
def run_transaction(self) -> None: ...
120-
def execute(self, *args, **kwargs): ...
121-
def read_table(
122-
self,
123-
table_name,
124-
index_col=...,
125-
coerce_float: bool = ...,
126-
parse_dates=...,
127-
columns=...,
128-
schema=...,
129-
chunksize=...,
130-
): ...
131-
def read_query(
132-
self,
133-
sql,
134-
index_col=...,
135-
coerce_float: bool = ...,
136-
parse_dates=...,
137-
params=...,
138-
chunksize=...,
139-
): ...
140-
def to_sql(
141-
self,
142-
frame,
143-
name,
144-
if_exists: str = ...,
145-
index: bool = ...,
146-
index_label=...,
147-
schema=...,
148-
chunksize=...,
149-
dtype=...,
150-
method=...,
151-
) -> None: ...
152-
@property
153-
def tables(self): ...
154-
def has_table(self, name, schema=...): ...
155-
def get_table(self, table_name, schema=...): ...
156-
def drop_table(self, table_name, schema=...) -> None: ...
157-
158-
class SQLiteTable(SQLTable):
159-
def __init__(self, *args, **kwargs): ...
160-
def sql_schema(self): ...
161-
def insert_statement(self): ...
162-
163-
class SQLiteDatabase(PandasSQL):
164-
is_cursor = ...
165-
con = ...
166-
def __init__(self, con, is_cursor: bool = ...) -> None: ...
167-
def run_transaction(self) -> None: ...
168-
def execute(self, *args, **kwargs): ...
169-
def read_query(
170-
self,
171-
sql,
172-
index_col=...,
173-
coerce_float: bool = ...,
174-
params=...,
175-
parse_dates=...,
176-
chunksize=...,
177-
): ...
178-
def to_sql(
179-
self,
180-
frame,
181-
name,
182-
if_exists: str = ...,
183-
index: bool = ...,
184-
index_label=...,
185-
schema=...,
186-
chunksize=...,
187-
dtype=...,
188-
method=...,
189-
) -> None: ...
190-
def has_table(self, name, schema=...): ...
191-
def get_table(self, table_name, schema=...) -> None: ...
192-
def drop_table(self, name, schema=...) -> None: ...
193-
194-
def get_schema(frame, name, keys=..., con=..., dtype=...): ...
102+
index_label: Hashable | Sequence[Hashable] | None = ...,
103+
chunksize: int | None = ...,
104+
dtype: DtypeArg | None = ...,
105+
method: str | Callable | None = ...,
106+
engine: str = ...,
107+
**engine_kwargs,
108+
) -> int | None: ...

0 commit comments

Comments
 (0)