Reputation: 21
I'm getting this error with this params:
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
import dask.dataframe as dd
from sqlalchemy.sql import text
query = text( "Some SQL statement" )
df = dd.read_sql_table(table=query,uri='Some postgreSQL DB',index_col='id')
Yields this error:
/usr/local/lib/python2.7/dist-packages/dask/dataframe/io/sql.pyc in read_sql_table(table, uri, index_col, divisions, npartitions, limits, columns, bytes_per_chunk, **kwargs)
73 schema=schema)
74
---> 75 index = (table.columns[index_col] if isinstance(index_col, six.string_types)
76 else index_col)
77 if not isinstance(index_col, six.string_types + (elements.Label,)):
TypeError: 'instancemethod' object has no attribute '__getitem__'
Someone knows what's the issue?
Upvotes: 2
Views: 413
Reputation: 28683
The table
parameter must either be an existing table (and so be a string or a sa.Table
instance) or a full sqlalchemy statement (e.g., sqlalchemy.sql.select()
), in which you define the full set of columns to be fetched. The reason for this is, that we don't attempt to parse a generic query here, which may be backend-specific. You could leverage sqlalchemy yourself to transform your text query into a structured statement for this function.
Upvotes: 1