Skip to content

Commit c7928f6

Browse files
SQL: fix + test handling columns argument in read_table
1 parent f7205b5 commit c7928f6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/io/sql.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ def read_table(table_name, con, meta=None, index_col=None, coerce_float=True,
340340
table = pandas_sql.read_table(table_name,
341341
index_col=index_col,
342342
coerce_float=coerce_float,
343-
parse_dates=parse_dates)
343+
parse_dates=parse_dates,
344+
columns=columns)
344345

345346
if table is not None:
346347
return table

pandas/io/tests/test_sql.py

+12
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,9 @@ def test_date_and_index(self):
460460
issubclass(df.IntDateCol.dtype.type, np.datetime64),
461461
"IntDateCol loaded with incorrect type")
462462

463+
463464
class TestSQLApi(_TestSQLApi):
465+
464466
"""Test the public API as it would be used directly
465467
"""
466468
flavor = 'sqlite'
@@ -501,8 +503,18 @@ def test_to_sql_index_label(self):
501503
self.assertEqual(frame.columns[0], 'other_label',
502504
"Specified index_label not written to database")
503505

506+
def test_read_table_columns(self):
507+
# test columns argument in read_table
508+
sql.to_sql(self.test_frame1, 'test_frame', self.conn)
509+
510+
cols = ['A', 'B']
511+
result = sql.read_table('test_frame', self.conn, columns=cols)
512+
self.assertEqual(result.columns.tolist(), cols,
513+
"Columns not correctly selected")
514+
504515

505516
class TestSQLLegacyApi(_TestSQLApi):
517+
506518
"""Test the public legacy API
507519
"""
508520
flavor = 'sqlite'

0 commit comments

Comments
 (0)