2

以下命令:

from odo import odo
odo(target='postgresql://{user}:{pass}@localhost/{server}::odo_dest_table',source='/home/username/Downloads/large_csv.csv')

产生以下错误:

  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/odo.py", line 91, in odo
    return into(target, source, **kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/multipledispatch/dispatcher.py", line 278, in __call__
    return func(*args, **kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/into.py", line 43, in wrapped
    return f(*args, **kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/into.py", line 149, in into_string_string
    return into(a, resource(b, **kwargs), **kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/multipledispatch/dispatcher.py", line 278, in __call__
    return func(*args, **kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/into.py", line 43, in wrapped
    return f(*args, **kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/into.py", line 138, in into_string
    dshape = discover(b)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/multipledispatch/dispatcher.py", line 278, in __call__
    return func(*args, **kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/backends/csv.py", line 377, in discover_csv
    df = csv_to_dataframe(c, nrows=nrows, **kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/backends/csv.py", line 295, in csv_to_dataframe
    return _csv_to_dataframe(c, dshape=dshape, chunksize=chunksize,
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/backends/csv.py", line 346, in _csv_to_dataframe
    kwargs = keyfilter(keywords(pd.read_csv).__contains__, kwargs)
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/site-packages/odo/utils.py", line 130, in keywords
    return inspect.getargspec(func).args
  File "/home/username/anaconda3/envs/odosimple/lib/python3.8/inspect.py", line 1083, in getargspec
    raise ValueError("Function has keyword-only parameters or annotations"
ValueError: Function has keyword-only parameters or annotations, use inspect.signature() API which can support them

Process finished with exit code 1

git clone我使用 pip ( -> )从 git 存储库安装到 conda env 中pip install .

4

1 回答 1

0

您的 CSV 文件的行数可能太少,因此 odo 无法对数据类型做出有根据的猜测。

https://odo.readthedocs.io/en/latest/datashape.html

当 odo 将此文件加载到新容器(DataFrame、新 SQL 表等)时,它需要知道源的数据类型,以便它可以创建匹配的目标。如果 CSV 文件很大,那么它只会查看前几百行并从中猜测数据类型。在这种情况下,它可能会错误地猜测余额列是整数类型,因为直到文件中的 Zelda,100.25 行很晚才看到十进制值。这将导致 odo 创建一个具有错误数据类型的目标,这会破坏传输。

尝试提供dshape关键字。例如,如果您的表有两列类型为 varchar 和 bigint,那么

odo(target='postgresql://{user}:{pass}@localhost/{server}::odo_dest_table',source='/home/username/Downloads/large_csv.csv', dshape='var * {a: string, b: int64}')

表和 CSV 中的列数必须相同且匹配,因此您可能必须在创建表时牢记 CSV 文件的结构。

我花了几个小时才发现:P

于 2020-10-21T08:05:43.437 回答