Skip to content

Commit

Permalink
fix: Don't error on empty iterators 1db7277
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Apr 28, 2024
1 parent be4fa7d commit 44d1673
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.10.1 - April 27, 2024
-----------------------

- fix: Version 1.10.0 seeks to the file's beginning, instead of to the original offset.
- fix: Version 1.10.0 errors on empty tables and seeks to the file's beginning, instead of to the original offset.
- fix: :meth:`.Number.csvify` returns a ``Decimal`` (or ``None``), instead of ``str``. :meth:`.Table.to_csv` with ``quoting=csv.QUOTE_NONNUMERIC`` now works.

1.10.0 - April 27, 2024
Expand Down
19 changes: 9 additions & 10 deletions agate/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,17 @@ def __init__(self, rows, column_names=None, column_types=None, row_names=None, _
# Validate column names
if column_names:
self._column_names = utils.deduplicate(column_names, column_names=True)
elif rows:
else:
rows = iter(rows)
try:
first_row = rows[0]
except TypeError:
# rows is an iterator.
first_row = next(rows)
except StopIteration:
self._column_names = tuple()
else:
rows = chain([first_row], rows)
self._column_names = tuple(utils.letter_name(i) for i in range(len(first_row)))
warnings.warn('Column names not specified. "%s" will be used as names.' % str(self._column_names),
RuntimeWarning, stacklevel=2)
else:
self._column_names = tuple()
self._column_names = tuple(utils.letter_name(i) for i in range(len(first_row)))
warnings.warn('Column names not specified. "%s" will be used as names.' % str(self._column_names),
RuntimeWarning, stacklevel=2)

len_column_names = len(self._column_names)

Expand All @@ -108,7 +107,7 @@ def __init__(self, rows, column_names=None, column_types=None, row_names=None, _
raise ValueError('Column types must be instances of DataType.')

if isinstance(column_types, TypeTester):
# In case rows is an iterator, in which case need to read it all into memory.
# Need to read all rows into memory.
rows = tuple(rows)
self._column_types = column_types.run(rows, self._column_names)
else:
Expand Down

0 comments on commit 44d1673

Please sign in to comment.