Skip to content

Commit ad97d27

Browse files
SQL: update some signatures and docstrings:
- remove meta kwarg from read_sql_table (see discussion in #6300) - remove flavor kwarg from read_sql (not necessary + not there in 0.13, so would have been API change) - update docstring of to_sql in generic with latest changes - enhance docstring of get_schema
1 parent 0312605 commit ad97d27

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

pandas/core/generic.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -928,10 +928,11 @@ def to_sql(self, name, con, flavor='sqlite', if_exists='fail', index=True,
928928
con : SQLAlchemy engine or DBAPI2 connection (legacy mode)
929929
Using SQLAlchemy makes it possible to use any DB supported by that
930930
library.
931-
If a DBAPI2 object is given, a supported SQL flavor must also be provided
931+
If a DBAPI2 object, only sqlite3 is supported.
932932
flavor : {'sqlite', 'mysql'}, default 'sqlite'
933933
The flavor of SQL to use. Ignored when using SQLAlchemy engine.
934-
Required when using DBAPI2 connection.
934+
'mysql' is deprecated and will be removed in future versions, but it
935+
will be further supported through SQLAlchemy engines.
935936
if_exists : {'fail', 'replace', 'append'}, default 'fail'
936937
- fail: If table exists, do nothing.
937938
- replace: If table exists, drop it, recreate it, and insert data.

pandas/io/sql.py

+25-24
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ def uquery(sql, con=None, cur=None, retry=True, params=None):
221221
#------------------------------------------------------------------------------
222222
#--- Read and write to DataFrames
223223

224-
def read_sql_table(table_name, con, meta=None, index_col=None,
225-
coerce_float=True, parse_dates=None, columns=None):
224+
def read_sql_table(table_name, con, index_col=None, coerce_float=True,
225+
parse_dates=None, columns=None):
226226
"""Read SQL database table into a DataFrame.
227227
228228
Given a table name and an SQLAlchemy engine, returns a DataFrame.
@@ -234,8 +234,6 @@ def read_sql_table(table_name, con, meta=None, index_col=None,
234234
Name of SQL table in database
235235
con : SQLAlchemy engine
236236
Sqlite DBAPI conncection mode not supported
237-
meta : SQLAlchemy meta, optional
238-
If omitted MetaData is reflected from engine
239237
index_col : string, optional
240238
Column to set as index
241239
coerce_float : boolean, default True
@@ -264,7 +262,7 @@ def read_sql_table(table_name, con, meta=None, index_col=None,
264262
265263
266264
"""
267-
pandas_sql = PandasSQLAlchemy(con, meta=meta)
265+
pandas_sql = PandasSQLAlchemy(con)
268266
table = pandas_sql.read_table(
269267
table_name, index_col=index_col, coerce_float=coerce_float,
270268
parse_dates=parse_dates, columns=columns)
@@ -292,11 +290,10 @@ def read_sql_query(sql, con, index_col=None, coerce_float=True, params=None,
292290
library.
293291
If a DBAPI2 object, only sqlite3 is supported.
294292
index_col : string, optional
295-
column name to use for the returned DataFrame object.
293+
Column name to use as index for the returned DataFrame object.
296294
coerce_float : boolean, default True
297295
Attempt to convert values to non-string, non-numeric objects (like
298296
decimal.Decimal) to floating point, useful for SQL result sets
299-
cur : depreciated, cursor is obtained from connection
300297
params : list, tuple or dict, optional
301298
List of parameters to pass to execute method.
302299
parse_dates : list or dict
@@ -325,8 +322,8 @@ def read_sql_query(sql, con, index_col=None, coerce_float=True, params=None,
325322
parse_dates=parse_dates)
326323

327324

328-
def read_sql(sql, con, index_col=None, flavor='sqlite', coerce_float=True,
329-
params=None, parse_dates=None, columns=None):
325+
def read_sql(sql, con, index_col=None, coerce_float=True, params=None,
326+
parse_dates=None, columns=None):
330327
"""
331328
Read SQL query or database table into a DataFrame.
332329
@@ -339,15 +336,10 @@ def read_sql(sql, con, index_col=None, flavor='sqlite', coerce_float=True,
339336
library.
340337
If a DBAPI2 object, only sqlite3 is supported.
341338
index_col : string, optional
342-
column name to use for the returned DataFrame object.
343-
flavor : string, {'sqlite', 'mysql'}
344-
The flavor of SQL to use. Ignored when using
345-
SQLAlchemy engine. Required when using DBAPI2 connection.
346-
'mysql' is still supported, but will be removed in future versions.
339+
column name to use as index for the returned DataFrame object.
347340
coerce_float : boolean, default True
348341
Attempt to convert values to non-string, non-numeric objects (like
349342
decimal.Decimal) to floating point, useful for SQL result sets
350-
cur : depreciated, cursor is obtained from connection
351343
params : list, tuple or dict, optional
352344
List of parameters to pass to execute method.
353345
parse_dates : list or dict
@@ -360,7 +352,8 @@ def read_sql(sql, con, index_col=None, flavor='sqlite', coerce_float=True,
360352
Especially useful with databases without native Datetime support,
361353
such as SQLite
362354
columns : list
363-
List of column names to select from sql table
355+
List of column names to select from sql table (only used when reading
356+
a table).
364357
365358
Returns
366359
-------
@@ -379,7 +372,7 @@ def read_sql(sql, con, index_col=None, flavor='sqlite', coerce_float=True,
379372
read_sql_query : Read SQL query into a DataFrame
380373
381374
"""
382-
pandas_sql = pandasSQL_builder(con, flavor=flavor)
375+
pandas_sql = pandasSQL_builder(con)
383376

384377
if 'select' in sql.lower():
385378
try:
@@ -419,8 +412,8 @@ def to_sql(frame, name, con, flavor='sqlite', if_exists='fail', index=True,
419412
If a DBAPI2 object, only sqlite3 is supported.
420413
flavor : {'sqlite', 'mysql'}, default 'sqlite'
421414
The flavor of SQL to use. Ignored when using SQLAlchemy engine.
422-
Required when using DBAPI2 connection.
423-
'mysql' is still supported, but will be removed in future versions.
415+
'mysql' is deprecated and will be removed in future versions, but it
416+
will be further supported through SQLAlchemy engines.
424417
if_exists : {'fail', 'replace', 'append'}, default 'fail'
425418
- fail: If table exists, do nothing.
426419
- replace: If table exists, drop it, recreate it, and insert data.
@@ -461,8 +454,8 @@ def has_table(table_name, con, flavor='sqlite'):
461454
If a DBAPI2 object, only sqlite3 is supported.
462455
flavor: {'sqlite', 'mysql'}, default 'sqlite'
463456
The flavor of SQL to use. Ignored when using SQLAlchemy engine.
464-
Required when using DBAPI2 connection.
465-
'mysql' is still supported, but will be removed in future versions.
457+
'mysql' is deprecated and will be removed in future versions, but it
458+
will be further supported through SQLAlchemy engines.
466459
467460
Returns
468461
-------
@@ -1090,15 +1083,23 @@ def _create_sql_schema(self, frame, table_name):
10901083

10911084
def get_schema(frame, name, flavor='sqlite', keys=None, con=None):
10921085
"""
1093-
Get the SQL db table schema for the given frame
1086+
Get the SQL db table schema for the given frame.
10941087
10951088
Parameters
10961089
----------
10971090
frame : DataFrame
1098-
name : name of SQL table
1091+
name : string
1092+
name of SQL table
10991093
flavor : {'sqlite', 'mysql'}, default 'sqlite'
1100-
keys : columns to use a primary key
1094+
The flavor of SQL to use. Ignored when using SQLAlchemy engine.
1095+
'mysql' is deprecated and will be removed in future versions, but it
1096+
will be further supported through SQLAlchemy engines.
1097+
keys : string or sequence
1098+
columns to use a primary key
11011099
con: an open SQL database connection object or an SQLAlchemy engine
1100+
Using SQLAlchemy makes it possible to use any DB supported by that
1101+
library.
1102+
If a DBAPI2 object, only sqlite3 is supported.
11021103
11031104
"""
11041105

pandas/io/tests/test_sql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def test_read_sql_iris(self):
340340
def test_legacy_read_frame(self):
341341
with tm.assert_produces_warning(FutureWarning):
342342
iris_frame = sql.read_frame(
343-
"SELECT * FROM iris", self.conn, flavor='sqlite')
343+
"SELECT * FROM iris", self.conn)
344344
self._check_iris_loaded_frame(iris_frame)
345345

346346
def test_to_sql(self):

0 commit comments

Comments
 (0)