@@ -76,32 +76,30 @@ def _parse_date_columns(data_frame, parse_dates):
76
76
return data_frame
77
77
78
78
79
- def execute (sql , con , cur = None , params = None , flavor = 'sqlite' ):
79
+ def execute (sql , con , cur = None , params = None ):
80
80
"""
81
81
Execute the given SQL query using the provided connection object.
82
82
83
83
Parameters
84
84
----------
85
85
sql : string
86
86
Query to be executed
87
- con : SQLAlchemy engine or DBAPI2 connection (legacy mode)
87
+ con : SQLAlchemy engine or sqlite3 DBAPI2 connection
88
88
Using SQLAlchemy makes it possible to use any DB supported by that
89
89
library.
90
- If a DBAPI2 object, a supported SQL flavor must also be provided
90
+ If a DBAPI2 object, only sqlite3 is supported.
91
91
cur : depreciated, cursor is obtained from connection
92
92
params : list or tuple, optional
93
93
List of parameters to pass to execute method.
94
- flavor : string "sqlite", "mysql"
95
- Specifies the flavor of SQL to use.
96
- Ignored when using SQLAlchemy engine. Required when using DBAPI2 connection.
94
+
97
95
Returns
98
96
-------
99
97
Results Iterable
100
98
"""
101
99
if cur is None :
102
- pandas_sql = pandasSQL_builder (con , flavor = flavor )
100
+ pandas_sql = pandasSQL_builder (con )
103
101
else :
104
- pandas_sql = pandasSQL_builder (cur , flavor = flavor , is_cursor = True )
102
+ pandas_sql = pandasSQL_builder (cur , is_cursor = True )
105
103
args = _convert_params (sql , params )
106
104
return pandas_sql .execute (* args )
107
105
@@ -235,7 +233,7 @@ def read_sql_table(table_name, con, meta=None, index_col=None,
235
233
table_name : string
236
234
Name of SQL table in database
237
235
con : SQLAlchemy engine
238
- Legacy mode not supported
236
+ Sqlite DBAPI conncection mode not supported
239
237
meta : SQLAlchemy meta, optional
240
238
If omitted MetaData is reflected from engine
241
239
index_col : string, optional
@@ -277,8 +275,8 @@ def read_sql_table(table_name, con, meta=None, index_col=None,
277
275
raise ValueError ("Table %s not found" % table_name , con )
278
276
279
277
280
- def read_sql_query (sql , con , index_col = None , flavor = 'sqlite' ,
281
- coerce_float = True , params = None , parse_dates = None ):
278
+ def read_sql_query (sql , con , index_col = None , coerce_float = True , params = None ,
279
+ parse_dates = None ):
282
280
"""Read SQL query into a DataFrame.
283
281
284
282
Returns a DataFrame corresponding to the result set of the query
@@ -289,15 +287,12 @@ def read_sql_query(sql, con, index_col=None, flavor='sqlite',
289
287
----------
290
288
sql : string
291
289
SQL query to be executed
292
- con : SQLAlchemy engine or DBAPI2 connection (legacy mode)
290
+ con : SQLAlchemy engine or sqlite3 DBAPI2 connection
293
291
Using SQLAlchemy makes it possible to use any DB supported by that
294
292
library.
295
- If a DBAPI2 object is given, a supported SQL flavor must also be provided
293
+ If a DBAPI2 object, only sqlite3 is supported.
296
294
index_col : string, optional
297
295
column name to use for the returned DataFrame object.
298
- flavor : string, {'sqlite', 'mysql'}
299
- The flavor of SQL to use. Ignored when using
300
- SQLAlchemy engine. Required when using DBAPI2 connection.
301
296
coerce_float : boolean, default True
302
297
Attempt to convert values to non-string, non-numeric objects (like
303
298
decimal.Decimal) to floating point, useful for SQL result sets
@@ -324,7 +319,7 @@ def read_sql_query(sql, con, index_col=None, flavor='sqlite',
324
319
read_sql
325
320
326
321
"""
327
- pandas_sql = pandasSQL_builder (con , flavor = flavor )
322
+ pandas_sql = pandasSQL_builder (con )
328
323
return pandas_sql .read_sql (
329
324
sql , index_col = index_col , params = params , coerce_float = coerce_float ,
330
325
parse_dates = parse_dates )
@@ -342,12 +337,13 @@ def read_sql(sql, con, index_col=None, flavor='sqlite', coerce_float=True,
342
337
con : SQLAlchemy engine or DBAPI2 connection (legacy mode)
343
338
Using SQLAlchemy makes it possible to use any DB supported by that
344
339
library.
345
- If a DBAPI2 object is given, a supported SQL flavor must also be provided
340
+ If a DBAPI2 object, only sqlite3 is supported.
346
341
index_col : string, optional
347
342
column name to use for the returned DataFrame object.
348
343
flavor : string, {'sqlite', 'mysql'}
349
344
The flavor of SQL to use. Ignored when using
350
345
SQLAlchemy engine. Required when using DBAPI2 connection.
346
+ 'mysql' is still supported, but will be removed in future versions.
351
347
coerce_float : boolean, default True
352
348
Attempt to convert values to non-string, non-numeric objects (like
353
349
decimal.Decimal) to floating point, useful for SQL result sets
@@ -417,13 +413,14 @@ def to_sql(frame, name, con, flavor='sqlite', if_exists='fail', index=True,
417
413
frame : DataFrame
418
414
name : string
419
415
Name of SQL table
420
- con : SQLAlchemy engine or DBAPI2 connection (legacy mode)
416
+ con : SQLAlchemy engine or sqlite3 DBAPI2 connection
421
417
Using SQLAlchemy makes it possible to use any DB supported by that
422
418
library.
423
- If a DBAPI2 object is given, a supported SQL flavor must also be provided
419
+ If a DBAPI2 object, only sqlite3 is supported.
424
420
flavor : {'sqlite', 'mysql'}, default 'sqlite'
425
421
The flavor of SQL to use. Ignored when using SQLAlchemy engine.
426
422
Required when using DBAPI2 connection.
423
+ 'mysql' is still supported, but will be removed in future versions.
427
424
if_exists : {'fail', 'replace', 'append'}, default 'fail'
428
425
- fail: If table exists, do nothing.
429
426
- replace: If table exists, drop it, recreate it, and insert data.
@@ -458,13 +455,14 @@ def has_table(table_name, con, flavor='sqlite'):
458
455
----------
459
456
table_name: string
460
457
Name of SQL table
461
- con: SQLAlchemy engine or DBAPI2 connection (legacy mode)
458
+ con: SQLAlchemy engine or sqlite3 DBAPI2 connection
462
459
Using SQLAlchemy makes it possible to use any DB supported by that
463
460
library.
464
- If a DBAPI2 object is given, a supported SQL flavor name must also be provided
461
+ If a DBAPI2 object, only sqlite3 is supported.
465
462
flavor: {'sqlite', 'mysql'}, default 'sqlite'
466
463
The flavor of SQL to use. Ignored when using SQLAlchemy engine.
467
464
Required when using DBAPI2 connection.
465
+ 'mysql' is still supported, but will be removed in future versions.
468
466
469
467
Returns
470
468
-------
@@ -476,6 +474,10 @@ def has_table(table_name, con, flavor='sqlite'):
476
474
table_exists = has_table
477
475
478
476
477
+ _MYSQL_WARNING = ("The 'mysql' flavor with DBAPI connection is deprecated "
478
+ "and will be removed in future versions. "
479
+ "MySQL will be further supported with SQLAlchemy engines." )
480
+
479
481
def pandasSQL_builder (con , flavor = None , meta = None , is_cursor = False ):
480
482
"""
481
483
Convenience function to return the correct PandasSQL subclass based on the
@@ -489,21 +491,14 @@ def pandasSQL_builder(con, flavor=None, meta=None, is_cursor=False):
489
491
if isinstance (con , sqlalchemy .engine .Engine ):
490
492
return PandasSQLAlchemy (con , meta = meta )
491
493
else :
492
- warnings .warn ("Not an SQLAlchemy engine, "
493
- "attempting to use as legacy DBAPI connection" )
494
- if flavor is None :
495
- raise ValueError (
496
- "PandasSQL must be created with an SQLAlchemy engine "
497
- "or a DBAPI2 connection and SQL flavor" )
498
- else :
499
- return PandasSQLLegacy (con , flavor , is_cursor = is_cursor )
494
+ if flavor == 'mysql' :
495
+ warnings .warn (_MYSQL_WARNING , FutureWarning )
496
+ return PandasSQLLegacy (con , flavor , is_cursor = is_cursor )
500
497
501
498
except ImportError :
502
- warnings .warn ("SQLAlchemy not installed, using legacy mode" )
503
- if flavor is None :
504
- raise SQLAlchemyRequired
505
- else :
506
- return PandasSQLLegacy (con , flavor , is_cursor = is_cursor )
499
+ if flavor == 'mysql' :
500
+ warnings .warn (_MYSQL_WARNING , FutureWarning )
501
+ return PandasSQLLegacy (con , flavor , is_cursor = is_cursor )
507
502
508
503
509
504
class PandasSQLTable (PandasObject ):
@@ -893,7 +888,7 @@ def _create_sql_schema(self, frame, table_name):
893
888
}
894
889
895
890
896
- _SAFE_NAMES_WARNING = ("The spaces in these column names will not be changed."
891
+ _SAFE_NAMES_WARNING = ("The spaces in these column names will not be changed. "
897
892
"In pandas versions < 0.14, spaces were converted to "
898
893
"underscores." )
899
894
@@ -991,6 +986,8 @@ class PandasSQLLegacy(PandasSQL):
991
986
def __init__ (self , con , flavor , is_cursor = False ):
992
987
self .is_cursor = is_cursor
993
988
self .con = con
989
+ if flavor is None :
990
+ flavor = 'sqlite'
994
991
if flavor not in ['sqlite' , 'mysql' ]:
995
992
raise NotImplementedError
996
993
else :
@@ -1098,6 +1095,8 @@ def get_schema(frame, name, flavor='sqlite', keys=None, con=None):
1098
1095
"""
1099
1096
1100
1097
if con is None :
1098
+ if flavor == 'mysql' :
1099
+ warnings .warn (_MYSQL_WARNING , FutureWarning )
1101
1100
return _get_schema_legacy (frame , name , flavor , keys )
1102
1101
1103
1102
pandas_sql = pandasSQL_builder (con = con , flavor = flavor )
0 commit comments