【问题标题】:Dask read_sql_table error: 'instancemethod' object has no attribute '__getitem__'Dask read_sql_table 错误:“instancemethod”对象没有属性“__getitem__”
【发布时间】:2018-05-09 04:04:48
【问题描述】:

我收到这个参数的错误:

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')

产生此错误:

/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__'

有人知道是什么问题吗?

【问题讨论】:

  • read_sql_table 作为第一个参数 table - 一个字符串:name_of_the_table。您传递的是 sql 查询而不是表名。

标签: python-2.7 dask dask-distributed


【解决方案1】:

table 参数必须是现有表(因此是字符串或 sa.Table 实例)或完整的 sqlalchemy 语句(例如,sqlalchemy.sql.select()),您可以在其中定义完整的列集以被取走。这样做的原因是,我们不尝试在这里解析通用的 query,这可能是后端特定的。您可以自己利用 sqlalchemy 将您的文本查询转换为该函数的结构化语句。

【讨论】:

    猜你喜欢
    • 2013-03-17
    • 2017-02-27
    • 2017-01-16
    • 2014-08-10
    • 1970-01-01
    • 2015-02-26
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多