turicas / rows

A common, beautiful interface to tabular data, no matter the format
GNU Lesser General Public License v3.0
865 stars 136 forks source link

Rows throw an error if the column name is a python reserved keyword #329

Open luzfcb opened 5 years ago

luzfcb commented 5 years ago

Rows throw an error if the column name is a python reserved keyword

(rows) luzfcb@fabio:~/Downloads$ rows csv-to-sqlite domains.csv domains.db
[domains.csv -> domains.db#domains] (detecting data types): 0.00 rows [00:00, ? rows/s]Traceback (most recent call last):
  File "/Users/luzfcb/.virtualenvs/pandas/bin/rows", line 10, in <module>
    sys.exit(cli())
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/rows/cli.py", line 667, in command_csv_to_sqlite
    schema=schema,
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/rows/utils.py", line 518, in csv_to_sqlite
    schema = rows.import_from_dicts(data).fields
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/rows/plugins/dicts.py", line 52, in import_from_dicts
    return create_table(chain([headers], data_rows), meta=meta, *args, **kwargs)
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/rows/plugins/utils.py", line 169, in create_table
    table = Table(fields=fields, meta=meta)
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/site-packages/rows/table.py", line 48, in __init__
    self.Row = namedtuple("Row", self.field_names)
  File "/Users/luzfcb/.virtualenvs/pandas/lib/python3.7/collections/__init__.py", line 364, in namedtuple
    raise ValueError('Type names and field names cannot be a '
ValueError: Type names and field names cannot be a keyword: 'as'

Sample csv that use the as python reserved keyword:

Domain;IP;Country;Organization;AS;OSH;Subdomains;First seen
grafana-srv.foobar.com.br;;;;;;0;Mar 2018

Related issue: #319