从MYSQL查询时dask read_sql错误

时间:2017-11-30 12:28:32

标签: python mysql dataframe sqlalchemy dask

我正在使用带有dask的python 2.7并尝试从远程计算机查询db表到dask数据帧

我在表中有一个多列索引,我尝试使用以下脚本

来读取它
ddf = dd.read_sql_table("table name", "mysql://user:pass@ip:port/Dbname",spesific column name).head()

收到以下错误

start = asanyarray(start) * 1.0 TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S32')
     

dtype('S32')dtype('S32')

我按照here

的说明得到了sqlalchemy uri

我不确定是什么问题,当我尝试通过另一列作为索引查询,并且只使用ddf head()时,我没有得到错误,当我尝试计算整个ddf时我得到相同的错误,我认为这是一个关于列不是唯一值的问题,我没有单列索引,但有多列,这里读取整个表的解决方案是什么?

感谢。

完全追溯

> Traceback (most recent call last):   File "path", line 28, in <module>
>     ddf = dd.read_sql_table("tablename", "mysql://user:pass@ip:port/dbname","indexcolumn")   File "file", line
> 123, in read_sql_table
>     divisions = np.linspace(mini, maxi, npartitions + 1).tolist()   File
> "/home/user/.local/lib/python2.7/site-packages/numpy/core/function_base.py",
> line 108, in linspace
>     start = asanyarray(start) * 1.0 TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S32')
> dtype('S32') dtype('S32')

1 个答案:

答案 0 :(得分:2)

对于您不提供进一步信息或仅指定分区数的情况,read_sql_table中的分区逻辑仅适用于数字,因为我们需要一种方法在最小值和最大值之间进行有序分割。 / p>

显然,但查询(获取最大值/分钟)是为这种情况返回一个字符串。 read_sql_table仍可以使用,但您需要定义要自行拆分的分区,并为它们提供divisions关键字,例如,

ddf = dd.read_sql_table("table name", "mysql://user:pass@ip:port/Dbname", 
    'index_col', divisions=['aardvark', 'llama', 'tapir', 'zebra']).head()

或者,有问题的字符串肯定看起来像一个数字,因此您可能需要更新表的模式以确保它被解释为数字。