|
| 1 | +import sqlite3 |
1 | 2 | from typing import (
|
2 | 3 | Any,
|
3 |
| - Mapping, |
4 |
| - Sequence, |
| 4 | + Callable, |
| 5 | + Generator, |
| 6 | + Iterable, |
| 7 | + Literal, |
| 8 | + overload, |
5 | 9 | )
|
6 | 10 |
|
7 | 11 | from pandas.core.base import PandasObject
|
8 | 12 | from pandas.core.frame import DataFrame
|
| 13 | +import sqlalchemy.engine |
| 14 | + |
| 15 | +from pandas._typing import ( |
| 16 | + DtypeArg, |
| 17 | + npt, |
| 18 | +) |
9 | 19 |
|
10 | 20 | class DatabaseError(IOError): ...
|
11 | 21 |
|
12 |
| -def execute(sql, con, cur=..., params=...): ... |
| 22 | +@overload |
13 | 23 | def read_sql_table(
|
14 | 24 | table_name: str,
|
15 |
| - con, |
| 25 | + con: str | sqlalchemy.engine.Connection | sqlite3.Connection, |
16 | 26 | schema: str | None = ...,
|
17 |
| - index_col: str | Sequence[str] | None = ..., |
| 27 | + index_col: str | list[str] | None = ..., |
18 | 28 | coerce_float: bool = ...,
|
19 |
| - parse_dates: Sequence[str] | Mapping[str, str] | None = ..., |
20 |
| - columns: Sequence[str] | None = ..., |
21 |
| - chunksize: int | None = ..., |
| 29 | + parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ..., |
| 30 | + columns: list[str] | None = ..., |
| 31 | + *, |
| 32 | + chunksize: int, |
| 33 | +) -> Generator[DataFrame, None, None]: ... |
| 34 | +@overload |
| 35 | +def read_sql_table( |
| 36 | + table_name: str, |
| 37 | + con: str | sqlalchemy.engine.Connection | sqlite3.Connection, |
| 38 | + schema: str | None = ..., |
| 39 | + index_col: str | list[str] | None = ..., |
| 40 | + coerce_float: bool = ..., |
| 41 | + parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ..., |
| 42 | + columns: list[str] | None = ..., |
| 43 | + chunksize: None = ..., |
22 | 44 | ) -> DataFrame: ...
|
| 45 | +@overload |
23 | 46 | def read_sql_query(
|
24 |
| - sql, |
25 |
| - con, |
26 |
| - schema: str | None = ..., |
27 |
| - index_col: str | Sequence[str] | None = ..., |
| 47 | + sql: str, |
| 48 | + con: str | sqlalchemy.engine.Connection | sqlite3.Connection, |
| 49 | + index_col: str | list[str] | None = ..., |
28 | 50 | coerce_float: bool = ...,
|
29 |
| - params=..., |
30 |
| - parse_dates: Sequence[str] | Mapping[str, str] | None = ..., |
31 |
| - chunksize: int | None = ..., |
| 51 | + params: list[str] | tuple[str, ...] | dict[str, str] | None = ..., |
| 52 | + parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ..., |
| 53 | + *, |
| 54 | + chunksize: int, |
| 55 | + dtype: DtypeArg | None = ..., |
| 56 | +) -> Generator[DataFrame, None, None]: ... |
| 57 | +@overload |
| 58 | +def read_sql_query( |
| 59 | + sql: str, |
| 60 | + con: str | sqlalchemy.engine.Connection | sqlite3.Connection, |
| 61 | + index_col: str | list[str] | None = ..., |
| 62 | + coerce_float: bool = ..., |
| 63 | + params: list[str] | tuple[str, ...] | dict[str, str] | None = ..., |
| 64 | + parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ..., |
| 65 | + chunksize: None = ..., |
| 66 | + dtype: DtypeArg | None = ..., |
32 | 67 | ) -> DataFrame: ...
|
| 68 | +@overload |
| 69 | +def read_sql( |
| 70 | + sql: str, |
| 71 | + con: str | sqlalchemy.engine.Connection | sqlite3.Connection, |
| 72 | + index_col: str | list[str] | None = ..., |
| 73 | + coerce_float: bool = ..., |
| 74 | + params: list[str] | tuple[str, ...] | dict[str, str] | None = ..., |
| 75 | + parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ..., |
| 76 | + columns: list[str] = ..., |
| 77 | + *, |
| 78 | + chunksize: int, |
| 79 | +) -> Generator[DataFrame, None, None]: ... |
| 80 | +@overload |
33 | 81 | def read_sql(
|
34 |
| - sql: str | Any, |
35 |
| - con: str | Any, |
36 |
| - index_col: str | Sequence[str] | None = ..., |
| 82 | + sql: str, |
| 83 | + con: str | sqlalchemy.engine.Connection | sqlite3.Connection, |
| 84 | + index_col: str | list[str] | None = ..., |
37 | 85 | coerce_float: bool = ...,
|
38 |
| - params: Sequence[str] | tuple[str, ...] | Mapping[str, str] | None = ..., |
39 |
| - parse_dates: Sequence[str] |
40 |
| - | Mapping[str, str] |
41 |
| - | Mapping[str, Mapping[str, Any]] |
42 |
| - | None = ..., |
43 |
| - columns: Sequence[str] = ..., |
44 |
| - chunksize: int = ..., |
| 86 | + params: list[str] | tuple[str, ...] | dict[str, str] | None = ..., |
| 87 | + parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ..., |
| 88 | + columns: list[str] = ..., |
| 89 | + chunksize: None = ..., |
45 | 90 | ) -> DataFrame: ...
|
46 |
| -def to_sql( |
47 |
| - frame, |
48 |
| - name, |
49 |
| - con, |
50 |
| - schema=..., |
51 |
| - if_exists: str = ..., |
52 |
| - index: bool = ..., |
53 |
| - index_label=..., |
54 |
| - chunksize=..., |
55 |
| - dtype=..., |
56 |
| - method=..., |
57 |
| -) -> None: ... |
58 |
| -def has_table(table_name, con, schema=...): ... |
59 |
| - |
60 |
| -table_exists = has_table |
61 |
| - |
62 |
| -def pandasSQL_builder(con, schema=..., meta=..., is_cursor: bool = ...): ... |
63 |
| - |
64 |
| -class SQLTable(PandasObject): |
65 |
| - name = ... |
66 |
| - pd_sql = ... |
67 |
| - prefix = ... |
68 |
| - frame = ... |
69 |
| - index = ... |
70 |
| - schema = ... |
71 |
| - if_exists = ... |
72 |
| - keys = ... |
73 |
| - dtype = ... |
74 |
| - table = ... |
75 |
| - def __init__( |
76 |
| - self, |
77 |
| - name, |
78 |
| - pandas_sql_engine, |
79 |
| - frame=..., |
80 |
| - index: bool = ..., |
81 |
| - if_exists: str = ..., |
82 |
| - prefix: str = ..., |
83 |
| - index_label=..., |
84 |
| - schema=..., |
85 |
| - keys=..., |
86 |
| - dtype=..., |
87 |
| - ) -> None: ... |
88 |
| - def exists(self): ... |
89 |
| - def sql_schema(self): ... |
90 |
| - def create(self) -> None: ... |
91 |
| - def insert_data(self): ... |
92 |
| - def insert(self, chunksize=..., method=...) -> None: ... |
93 |
| - def read( |
94 |
| - self, coerce_float: bool = ..., parse_dates=..., columns=..., chunksize=... |
95 |
| - ): ... |
96 | 91 |
|
97 | 92 | class PandasSQL(PandasObject):
|
98 |
| - def read_sql(self, *args, **kwargs) -> None: ... |
| 93 | + def read_sql(self, *args, **kwargs): ... |
99 | 94 | def to_sql(
|
100 | 95 | self,
|
101 |
| - frame, |
102 |
| - name, |
103 |
| - if_exists: str = ..., |
| 96 | + frame: DataFrame, |
| 97 | + name: str, |
| 98 | + if_exists: Literal["fail", "replace", "append"] = ..., |
104 | 99 | index: bool = ...,
|
105 | 100 | index_label=...,
|
106 |
| - schema=..., |
| 101 | + schema: str | None = ..., |
107 | 102 | chunksize=...,
|
108 |
| - dtype=..., |
109 |
| - method=..., |
110 |
| - ) -> None: ... |
| 103 | + dtype: DtypeArg | None = ..., |
| 104 | + method: Literal["multi"] |
| 105 | + | Callable[[SQLTable, Any, list[str], Iterable], int | None] |
| 106 | + | None = ..., |
| 107 | + ) -> int | None: ... |
111 | 108 |
|
112 |
| -class SQLDatabase(PandasSQL): |
113 |
| - connectable = ... |
114 |
| - meta = ... |
115 |
| - def __init__(self, engine, schema=..., meta=...) -> None: ... |
116 |
| - def run_transaction(self) -> None: ... |
117 |
| - def execute(self, *args, **kwargs): ... |
118 |
| - def read_table( |
119 |
| - self, |
120 |
| - table_name, |
121 |
| - index_col=..., |
122 |
| - coerce_float: bool = ..., |
123 |
| - parse_dates=..., |
124 |
| - columns=..., |
125 |
| - schema=..., |
126 |
| - chunksize=..., |
127 |
| - ): ... |
128 |
| - def read_query( |
129 |
| - self, |
130 |
| - sql, |
131 |
| - index_col=..., |
132 |
| - coerce_float: bool = ..., |
133 |
| - parse_dates=..., |
134 |
| - params=..., |
135 |
| - chunksize=..., |
136 |
| - ): ... |
137 |
| - def to_sql( |
| 109 | +class SQLTable(PandasObject): |
| 110 | + name: str |
| 111 | + pd_sql: PandasSQL # pandas SQL interface |
| 112 | + prefix: str |
| 113 | + frame: DataFrame | None |
| 114 | + index: list[str] |
| 115 | + schema: str |
| 116 | + if_exists: Literal["fail", "replace", "append"] |
| 117 | + keys: list[str] |
| 118 | + dtype: DtypeArg | None |
| 119 | + table: Any # sqlalchemy.Table |
| 120 | + def __init__( |
138 | 121 | self,
|
139 |
| - frame, |
140 |
| - name, |
141 |
| - if_exists: str = ..., |
142 |
| - index: bool = ..., |
143 |
| - index_label=..., |
144 |
| - schema=..., |
145 |
| - chunksize=..., |
146 |
| - dtype=..., |
147 |
| - method=..., |
| 122 | + name: str, |
| 123 | + pandas_sql_engine: PandasSQL, |
| 124 | + frame: DataFrame | None = ..., |
| 125 | + index: bool | str | list[str] | None = ..., |
| 126 | + if_exists: Literal["fail", "replace", "append"] = ..., |
| 127 | + prefix: str = ..., |
| 128 | + index_label: str | list[str] | None = ..., |
| 129 | + schema: str | None = ..., |
| 130 | + keys: str | list[str] | None = ..., |
| 131 | + dtype: DtypeArg | None = ..., |
148 | 132 | ) -> None: ...
|
149 |
| - @property |
150 |
| - def tables(self): ... |
151 |
| - def has_table(self, name, schema=...): ... |
152 |
| - def get_table(self, table_name, schema=...): ... |
153 |
| - def drop_table(self, table_name, schema=...) -> None: ... |
154 |
| - |
155 |
| -class SQLiteTable(SQLTable): |
156 |
| - def __init__(self, *args, **kwargs): ... |
157 |
| - def sql_schema(self): ... |
158 |
| - def insert_statement(self): ... |
159 |
| - |
160 |
| -class SQLiteDatabase(PandasSQL): |
161 |
| - is_cursor = ... |
162 |
| - con = ... |
163 |
| - def __init__(self, con, is_cursor: bool = ...) -> None: ... |
164 |
| - def run_transaction(self) -> None: ... |
165 |
| - def execute(self, *args, **kwargs): ... |
166 |
| - def read_query( |
| 133 | + def exists(self) -> bool: ... |
| 134 | + def sql_schema(self) -> str: ... |
| 135 | + def create(self) -> None: ... |
| 136 | + def insert_data(self) -> tuple[list[str], list[npt.NDArray]]: ... |
| 137 | + def insert( |
| 138 | + self, chunksize: int | None = ..., method: str | None = ... |
| 139 | + ) -> int | None: ... |
| 140 | + def read( |
167 | 141 | self,
|
168 |
| - sql, |
169 |
| - index_col=..., |
170 | 142 | coerce_float: bool = ...,
|
171 |
| - params=..., |
172 |
| - parse_dates=..., |
173 |
| - chunksize=..., |
174 |
| - ): ... |
175 |
| - def to_sql( |
176 |
| - self, |
177 |
| - frame, |
178 |
| - name, |
179 |
| - if_exists: str = ..., |
180 |
| - index: bool = ..., |
181 |
| - index_label=..., |
182 |
| - schema=..., |
183 |
| - chunksize=..., |
184 |
| - dtype=..., |
185 |
| - method=..., |
186 |
| - ) -> None: ... |
187 |
| - def has_table(self, name, schema=...): ... |
188 |
| - def get_table(self, table_name, schema=...) -> None: ... |
189 |
| - def drop_table(self, name, schema=...) -> None: ... |
190 |
| - |
191 |
| -def get_schema(frame, name, keys=..., con=..., dtype=...): ... |
| 143 | + parse_dates: bool | list[str] | None = ..., |
| 144 | + columns: list[str] | None = ..., |
| 145 | + chunksize: int | None = ..., |
| 146 | + ) -> DataFrame | Generator[DataFrame, None, None]: ... |
0 commit comments