Skip to content

Commit

Permalink
Fix #469 by catching StopIteration
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Jan 23, 2016
1 parent bcd30a6 commit 6ed9704
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions csvkit/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,28 +209,26 @@ def from_csv(cls, f, name='from_csv_table', snifflimit=None, column_ids=None, bl
f = six.StringIO(contents)
rows = agate.reader(f, **kwargs)

if no_header_row:
# Peek at a row to infer column names from
row = next(rows)
try:
if no_header_row:
# Peek at a row to infer column names from, and put it back on top
row = next(rows)
rows = itertools.chain([row], rows)
headers = make_default_headers(len(row))
else:
headers = next(rows)
except StopIteration:
# The file is `/dev/null`.
headers = []
pass

headers = make_default_headers(len(row))
if no_header_row or column_ids:
column_ids = parse_column_identifiers(column_ids, headers, zero_based)
headers = [headers[c] for c in column_ids]
data_columns = [[] for c in headers]

# Put row back on top
rows = itertools.chain([row], rows)
else:
headers = next(rows)

if column_ids:
column_ids = parse_column_identifiers(column_ids, headers, zero_based)
headers = [headers[c] for c in column_ids]
else:
column_ids = range(len(headers))

data_columns = [[] for c in headers]
column_ids = range(len(headers))

data_columns = [[] for c in headers]
width = len(data_columns)

for i, row in enumerate(rows):
Expand Down

0 comments on commit 6ed9704

Please sign in to comment.