@@ -310,8 +310,8 @@ def read_table(table_name, con, meta=None, index_col=None, coerce_float=True,
310
310
Legacy mode not supported
311
311
meta : SQLAlchemy meta, optional
312
312
If omitted MetaData is reflected from engine
313
- index_col : string, optional
314
- Column to set as index
313
+ index_col : string or sequence of strings , optional
314
+ Column(s) to set as index.
315
315
coerce_float : boolean, default True
316
316
Attempt to convert values to non-string, non-numeric objects (like
317
317
decimal.Decimal) to floating point. Can result in loss of Precision.
@@ -324,7 +324,7 @@ def read_table(table_name, con, meta=None, index_col=None, coerce_float=True,
324
324
to the keyword arguments of :func:`pandas.to_datetime`
325
325
Especially useful with databases without native Datetime support,
326
326
such as SQLite
327
- columns : list
327
+ columns : list, optional
328
328
List of column names to select from sql table
329
329
330
330
Returns
@@ -466,7 +466,7 @@ def read(self, coerce_float=True, parse_dates=None, columns=None):
466
466
from sqlalchemy import select
467
467
cols = [self .table .c [n ] for n in columns ]
468
468
if self .index is not None :
469
- cols .insert (0 , self .table .c [self .index ])
469
+ [ cols .insert (0 , self .table .c [idx ]) for idx in self .index [:: - 1 ]]
470
470
sql_select = select (cols )
471
471
else :
472
472
sql_select = self .table .select ()
@@ -483,14 +483,10 @@ def read(self, coerce_float=True, parse_dates=None, columns=None):
483
483
if self .index is not None :
484
484
self .frame .set_index (self .index , inplace = True )
485
485
486
- # Assume if the index in prefix_index format, we gave it a name
487
- # and should return it nameless
488
- if self .index == self .prefix + '_index' :
489
- self .frame .index .name = None
490
-
491
486
return self .frame
492
487
493
488
def _index_name (self , index , index_label ):
489
+ # for writing: index=True to include index in sql table
494
490
if index is True :
495
491
nlevels = self .frame .index .nlevels
496
492
# if index_label is specified, set this as index name(s)
@@ -510,7 +506,10 @@ def _index_name(self, index, index_label):
510
506
return [l if l is not None else "level_{0}" .format (i )
511
507
for i , l in enumerate (self .frame .index .names )]
512
508
509
+ # for reading: index=(list of) string to specify column to set as index
513
510
elif isinstance (index , string_types ):
511
+ return [index ]
512
+ elif isinstance (index , list ):
514
513
return index
515
514
else :
516
515
return None
0 commit comments